forge
Explore
Log in

Don't you dare go Hollow

One packed cell for the four skip/pu-edge mi maps, one pass for around_mi

Browse files at this commit

dcb88a28afecf7237b31395b0c10f08aa1082d5bAhmet Kaan GümüşParent: cb9db45
  • perf
    • one packed cell for the four skip/pu-edge mi maps, one pass for around_mi
Show full message
perf(av1): one packed cell for the four skip/pu-edge mi maps, one pass for around_mi

Block publication walked the same mi rectangle once per map. `skip`, its
written-instrument bit, and the covering block's origin and dims are written
by `fill_skip_grid_rect` and by nothing else, so they become one 8-byte
`BlkCell` and one fill per row instead of four -- the deblocker's `pu_edge`
also reads origin and dims off one cache line now.

`around_mi`/`around_mi_rect` gathered the neighbour coded/DC-sign state one
plane at a time, so the three planes of a cell (one `[Neighbour; 3]`) were
loaded three times; one pass over the cells accumulates all three.

Byte-exact: 12/12 gate hashes at 1, 4 and 16 threads. seg4k instructions:u
405.019 -> 402.414 G at 1 thread (-0.64%) and 408.299 -> 405.731 G at
(16,4,2) (-0.63%); task-clock at (16,4,2) 41.08 -> 40.78/41.03 s interleaved.
crates/ec-av1/src/decode.rsmodified+70 -50
@@ -6283,6 +6283,19 @@ const SKIP_CONTEXTS: [[usize; 5]; 5] = [
6283 [3, 5, 5, 5, 6],6283 [3, 5, 5, 5, 6],
6284 ];6284 ];
6285 6285
6286+/// The `skip` flag, its written-instrument bit, and the covering coded
6287+/// block's origin and dims, packed into ONE 8-byte cell (lane-publish): the
6288+/// four maps are written together by `Neighbours::fill_skip_grid_rect` and by
6289+/// nothing else, so a block's row is one fill instead of four, and the
6290+/// deblocker's `pu_edge` reads origin and dims off one cache line.
6291+#[derive(Clone, Copy)]
6292+struct BlkCell {
6293+ skip: bool,
6294+ written: bool,
6295+ org: [u16; 2],
6296+ dim: [u8; 2],
6297+}
6298+
6286 /// The neighbour state a block's contexts are read from — a duplicate of6299 /// The neighbour state a block's contexts are read from — a duplicate of
6287 /// [`crate::tile`]'s own private `Neighbours` (that module is another lane's6300 /// [`crate::tile`]'s own private `Neighbours` (that module is another lane's
6288 /// territory this round), kept at the same two granularities the real writer6301 /// territory this round), kept at the same two granularities the real writer
@@ -6418,27 +6431,25 @@ struct Neighbours {
6418 /// grain [`Self::record_mi`] already writes at), read back at 8x86431 /// grain [`Self::record_mi`] already writes at), read back at 8x8
6419 /// granularity by [`apply_cdef`] since `skip` is constant across every6432 /// granularity by [`apply_cdef`] since `skip` is constant across every
6420 /// mi cell one coded block covers.6433 /// mi cell one coded block covers.
6421- skip_grid: Vec<bool>,6434+ /// The four per-mi maps [`Neighbours::blk_grid`] packs, in one cell.
6422 /// lane-cdefstrip r1 instrument: whether any coded block actually WROTE6435 /// lane-cdefstrip r1 instrument: whether any coded block actually WROTE
6423- /// [`Self::skip_grid`] at this mi cell during this frame. A fresh6436+ /// the `skip` bit at this mi cell during this frame. A fresh
6424 /// `Neighbours` seeds `skip_grid` all-`false` ("not skip"), so a decode6437 /// `Neighbours` seeds `skip_grid` all-`false` ("not skip"), so a decode
6425 /// arm that forgets [`Self::fill_skip_grid_rect`] silently makes6438 /// arm that forgets [`Self::fill_skip_grid_rect`] silently makes
6426 /// [`apply_cdef`] filter an 8x8 unit libaom's `is_8x8_block_skip`6439 /// [`apply_cdef`] filter an 8x8 unit libaom's `is_8x8_block_skip`
6427 /// (`cdef.c:29-38`) excludes -- exactly the lane-cdef defect, and6440 /// (`cdef.c:29-38`) excludes -- exactly the lane-cdef defect, and
6428 /// unobservable from the pixels alone. Counted by6441 /// unobservable from the pixels alone. Counted by
6429 /// [`cdef_unwritten_skip_units`].6442 /// [`cdef_unwritten_skip_units`].
6430- skip_written: Vec<bool>,
6431 /// Per-4x4-mi origin `(mi_row, mi_col)` of the coded (prediction) block6443 /// Per-4x4-mi origin `(mi_row, mi_col)` of the coded (prediction) block
6432 /// covering that cell -- spec 7.14.2's `isBlockEdge`/libaom `pu_edge`,6444 /// covering that cell -- spec 7.14.2's `isBlockEdge`/libaom `pu_edge`,
6433 /// which re-enables the loop filter at a prediction boundary between two6445 /// which re-enables the loop filter at a prediction boundary between two
6434 /// skipped inter blocks (lane-mergefix r4). Written by6446 /// skipped inter blocks (lane-mergefix r4). Written by
6435 /// [`Self::fill_skip_grid_rect`], whose `at_mi` IS that origin.6447 /// [`Self::fill_skip_grid_rect`], whose `at_mi` IS that origin.
6436- blk_org_grid: Vec<[u16; 2]>,
6437 /// Per-4x4-mi `(width, height)` in mi units of the coded block covering6448 /// Per-4x4-mi `(width, height)` in mi units of the coded block covering
6438 /// that cell -- the other half of `pu_edge`: libaom tests the edge6449 /// that cell -- the other half of `pu_edge`: libaom tests the edge
6439 /// coordinate against the block's size in the FILTERED plane's own6450 /// coordinate against the block's size in the FILTERED plane's own
6440 /// pixels, which for chroma is `max(luma_dim / 2, 4)` (lane-t900 r30b).6451 /// pixels, which for chroma is `max(luma_dim / 2, 4)` (lane-t900 r30b).
6441- blk_dim_grid: Vec<[u8; 2]>,6452+ blk_grid: Vec<BlkCell>,
6442 skip_grid_cols_mi: usize,6453 skip_grid_cols_mi: usize,
6443 /// Per-4x4-mi luma transform width in pixels (8/16/32/64) -- this decoder6454 /// Per-4x4-mi luma transform width in pixels (8/16/32/64) -- this decoder
6444 /// never splits a coded block's transform below its own size (round 2:6455 /// never splits a coded block's transform below its own size (round 2:
@@ -6560,10 +6571,10 @@ impl Neighbours {
6560 left_filter: vec![[3u8; 2]; rows * (SUB / MI)],6571 left_filter: vec![[3u8; 2]; rows * (SUB / MI)],
6561 mi_cols,6572 mi_cols,
6562 mi_rows,6573 mi_rows,
6563- skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],6574+ blk_grid: vec![
6564- skip_written: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],6575+ BlkCell { skip: false, written: false, org: [0; 2], dim: [1; 2] };
6565- blk_org_grid: vec![[0u16; 2]; cols * (SUB / MI) * rows * (SUB / MI)],6576+ cols * (SUB / MI) * rows * (SUB / MI)
6566- blk_dim_grid: vec![[1u8; 2]; cols * (SUB / MI) * rows * (SUB / MI)],6577+ ],
6567 skip_grid_cols_mi: cols * (SUB / MI),6578 skip_grid_cols_mi: cols * (SUB / MI),
6568 tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],6579 tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
6569 tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],6580 tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
@@ -6971,10 +6982,17 @@ impl Neighbours {
6971 }6982 }
6972 for rr in 0..h_mi {6983 for rr in 0..h_mi {
6973 let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c;6984 let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c;
6974- fill_span(&mut self.skip_grid, start, w_mi, skip);6985+ fill_span(
6975- fill_span(&mut self.skip_written, start, w_mi, true);6986+ &mut self.blk_grid,
6976- fill_span(&mut self.blk_org_grid, start, w_mi, [mi_r as u16, mi_c as u16]);6987+ start,
6977- fill_span(&mut self.blk_dim_grid, start, w_mi, [w_mi as u8, h_mi as u8]);6988+ w_mi,
6989+ BlkCell {
6990+ skip,
6991+ written: true,
6992+ org: [mi_r as u16, mi_c as u16],
6993+ dim: [w_mi as u8, h_mi as u8],
6994+ },
6995+ );
6978 }6996 }
6979 }6997 }
6980 6998
@@ -6988,10 +7006,9 @@ impl Neighbours {
6988 /// filter's `curr_skipped`/`pv_skip_txfm` (spec 7.14.2) want, since a7006 /// filter's `curr_skipped`/`pv_skip_txfm` (spec 7.14.2) want, since a
6989 /// filtered edge's two sides are each exactly one coded block wide.7007 /// filtered edge's two sides are each exactly one coded block wide.
6990 fn skip_at(&self, mi_r: usize, mi_c: usize) -> bool {7008 fn skip_at(&self, mi_r: usize, mi_c: usize) -> bool {
6991- self.skip_grid7009+ self.blk_grid
6992 .get(mi_r * self.skip_grid_cols_mi + mi_c)7010 .get(mi_r * self.skip_grid_cols_mi + mi_c)
6993- .copied()7011+ .is_some_and(|c| c.skip)
6994- .unwrap_or(false)
6995 }7012 }
6996 7013
6997 /// The `skip_txfm` context of a block whose top-left mi cell is7014 /// The `skip_txfm` context of a block whose top-left mi cell is
@@ -7007,10 +7024,9 @@ impl Neighbours {
7007 fn is_skip_txfm(&self, mi_r: usize, mi_c: usize) -> bool {7024 fn is_skip_txfm(&self, mi_r: usize, mi_c: usize) -> bool {
7008 (0..2).all(|rr| {7025 (0..2).all(|rr| {
7009 (0..2).all(|cc| {7026 (0..2).all(|cc| {
7010- self.skip_grid7027+ self.blk_grid
7011 .get((mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc))7028 .get((mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc))
7012- .copied()7029+ .is_some_and(|c| c.skip)
7013- .unwrap_or(false)
7014 })7030 })
7015 })7031 })
7016 }7032 }
@@ -7262,19 +7278,21 @@ impl Neighbours {
7262 /// units, for the same reason [`Self::record_mi`] does.7278 /// units, for the same reason [`Self::record_mi`] does.
7263 fn around_mi(&self, (mi_r, mi_c): (usize, usize), side: usize) -> [(bool, bool, i32); 3] {7279 fn around_mi(&self, (mi_r, mi_c): (usize, usize), side: usize) -> [(bool, bool, i32); 3] {
7264 let side_mi = side / MI;7280 let side_mi = side / MI;
7265- std::array::from_fn(|plane| {7281+ // One pass over the cells accumulating all three planes, not one pass
7266- let mut above_coded = false;7282+ // per plane: the three planes of a cell live in the same
7267- let mut left_coded = false;7283+ // `[Neighbour; 3]` (6 bytes), so the per-plane form loaded the same
7268- let mut vote = 0;7284+ // cache lines three times (lane-publish).
7285+ let mut out = [(false, false, 0i32); 3];
7269 for cell in 0..side_mi {7286 for cell in 0..side_mi {
7270- let above = &self.above[mi_c + cell][plane];7287+ let above = &self.above[mi_c + cell];
7271- let left = &self.left[mi_r + cell][plane];7288+ let left = &self.left[mi_r + cell];
7272- above_coded |= above.level != 0;7289+ for (plane, o) in out.iter_mut().enumerate() {
7273- left_coded |= left.level != 0;7290+ o.0 |= above[plane].level != 0;
7274- vote += dc_vote(above.dc) + dc_vote(left.dc);7291+ o.1 |= left[plane].level != 0;
7292+ o.2 += dc_vote(above[plane].dc) + dc_vote(left[plane].dc);
7275 }7293 }
7276- (above_coded, left_coded, vote)7294+ }
7277- })7295+ out
7278 }7296 }
7279 7297
7280 /// [`Self::around`] with independent above (`w`)/left (`h`) extents, in7298 /// [`Self::around`] with independent above (`w`)/left (`h`) extents, in
@@ -7288,21 +7306,25 @@ impl Neighbours {
7288 /// mode-info units, mirroring [`Self::around_mi`].7306 /// mode-info units, mirroring [`Self::around_mi`].
7289 fn around_mi_rect(&self, (mi_r, mi_c): (usize, usize), w: usize, h: usize) -> [(bool, bool, i32); 3] {7307 fn around_mi_rect(&self, (mi_r, mi_c): (usize, usize), w: usize, h: usize) -> [(bool, bool, i32); 3] {
7290 let (w_mi, h_mi) = (w / MI, h / MI);7308 let (w_mi, h_mi) = (w / MI, h / MI);
7291- std::array::from_fn(|plane| {7309+ // [`Self::around_mi`]'s single pass, with the two extents split.
7292- let mut above_coded = false;7310+ let mut out = [(false, false, 0i32); 3];
7293- let mut left_coded = false;
7294- let mut vote = 0;
7295 for cell in 0..w_mi {7311 for cell in 0..w_mi {
7296- let above = &self.above[mi_c + cell][plane];7312+ let above = &self.above[mi_c + cell];
7297- above_coded |= above.level != 0;7313+ for (plane, o) in out.iter_mut().enumerate() {
7298- vote += dc_vote(above.dc);7314+ o.0 |= above[plane].level != 0;
7315+ o.2 += dc_vote(above[plane].dc);
7316+ }
7299 }7317 }
7300 for cell in 0..h_mi {7318 for cell in 0..h_mi {
7301- let left = &self.left[mi_r + cell][plane];7319+ let left = &self.left[mi_r + cell];
7302- left_coded |= left.level != 0;7320+ for (plane, o) in out.iter_mut().enumerate() {
7303- vote += dc_vote(left.dc);7321+ o.1 |= left[plane].level != 0;
7322+ o.2 += dc_vote(left[plane].dc);
7323+ }
7304 }7324 }
7305 if crate::envflags::env_flag!("EC_DCDUMP") {7325 if crate::envflags::env_flag!("EC_DCDUMP") {
7326+ for (plane, o) in out.iter().enumerate() {
7327+ let vote = o.2;
7306 let ab: Vec<String> = (0..w_mi)7328 let ab: Vec<String> = (0..w_mi)
7307 .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level))7329 .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level))
7308 .collect();7330 .collect();
@@ -7311,8 +7333,8 @@ impl Neighbours {
7311 .collect();7333 .collect();
7312 eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(","));7334 eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(","));
7313 }7335 }
7314- (above_coded, left_coded, vote)7336+ }
7315- })7337+ out
7316 }7338 }
7317 7339
7318 /// The luma `txb_skip_ctx` of a transform unit smaller than its own block7340 /// The luma `txb_skip_ctx` of a transform unit smaller than its own block
@@ -18025,8 +18047,8 @@ fn edge_params_body(
18025 // bottom/right mi does not start there. Comparing mi origins instead is18047 // bottom/right mi does not start there. Comparing mi origins instead is
18026 // the same test only while the block's own origin is aligned to its18048 // the same test only while the block's own origin is aligned to its
18027 // size, which a 4x4 luma block read at the `| 1` mi is not.18049 // size, which a 4x4 luma block read at the `| 1` mi is not.
18028- let cur_org = n.blk_org_grid[mi_r * n.skip_grid_cols_mi + mi_c];18050+ let cur_cell = n.blk_grid[mi_r * n.skip_grid_cols_mi + mi_c];
18029- let cur_dim = n.blk_dim_grid[mi_r * n.skip_grid_cols_mi + mi_c];18051+ let (cur_org, cur_dim) = (cur_cell.org, cur_cell.dim);
18030 let (org_px, dim_mi) = if c.dir == 0 {18052 let (org_px, dim_mi) = if c.dir == 0 {
18031 (usize::from(cur_org[1]), usize::from(cur_dim[0]))18053 (usize::from(cur_org[1]), usize::from(cur_dim[0]))
18032 } else {18054 } else {
@@ -19345,10 +19367,9 @@ fn apply_cdef(
19345 if (0..2).any(|rr| {19367 if (0..2).any(|rr| {
19346 (0..2).any(|cc| {19368 (0..2).any(|cc| {
19347 !skip_grid19369 !skip_grid
19348- .skip_written19370+ .blk_grid
19349 .get((r + rr) * skip_grid.skip_grid_cols_mi + (c + cc))19371 .get((r + rr) * skip_grid.skip_grid_cols_mi + (c + cc))
19350- .copied()19372+ .map_or(true, |x| x.written)
19351- .unwrap_or(true)
19352 })19373 })
19353 }) {19374 }) {
19354 CDEF_UNWRITTEN_SKIP_UNITS.with(|c2| c2.set(c2.get() + 1));19375 CDEF_UNWRITTEN_SKIP_UNITS.with(|c2| c2.set(c2.get() + 1));
@@ -19358,10 +19379,9 @@ fn apply_cdef(
19358 }19379 }
19359 let cell = |rr: usize, cc: usize| {19380 let cell = |rr: usize, cc: usize| {
19360 skip_grid19381 skip_grid
19361- .skip_grid19382+ .blk_grid
19362 .get((r + rr) * skip_grid.skip_grid_cols_mi + (c + cc))19383 .get((r + rr) * skip_grid.skip_grid_cols_mi + (c + cc))
19363- .copied()19384+ .is_some_and(|x| x.skip)
19364- .unwrap_or(false)
19365 };19385 };
19366 let first = cell(0, 0);19386 let first = cell(0, 0);
19367 if (0..2).any(|rr| (0..2).any(|cc| cell(rr, cc) != first)) {19387 if (0..2).any(|rr| (0..2).any(|cc| cell(rr, cc) != first)) {