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 commit1 changed file +75 -55
- crates/ec-av1/src/decode.rs +75 -55
crates/ec-av1/src/decode.rsmodified+75 -55
| @@ -6314,6 +6314,19 @@ const SKIP_CONTEXTS: [[usize; 5]; 5] = [ | ||
| 6314 | 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 | 6330 | /// The neighbour state a block's contexts are read from — a duplicate of |
| 6318 | 6331 | /// [`crate::tile`]'s own private `Neighbours` (that module is another lane's |
| 6319 | 6332 | /// territory this round), kept at the same two granularities the real writer |
| @@ -6449,27 +6462,25 @@ struct Neighbours { | ||
| 6449 | 6462 | /// grain [`Self::record_mi`] already writes at), read back at 8x8 |
| 6450 | 6463 | /// granularity by [`apply_cdef`] since `skip` is constant across every |
| 6451 | 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 | 6466 | /// 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 | |
| 6455 | 6468 | /// `Neighbours` seeds `skip_grid` all-`false` ("not skip"), so a decode |
| 6456 | 6469 | /// arm that forgets [`Self::fill_skip_grid_rect`] silently makes |
| 6457 | 6470 | /// [`apply_cdef`] filter an 8x8 unit libaom's `is_8x8_block_skip` |
| 6458 | 6471 | /// (`cdef.c:29-38`) excludes -- exactly the lane-cdef defect, and |
| 6459 | 6472 | /// unobservable from the pixels alone. Counted by |
| 6460 | 6473 | /// [`cdef_unwritten_skip_units`]. |
| 6461 | - skip_written: Vec<bool>, | |
| 6462 | 6474 | /// Per-4x4-mi origin `(mi_row, mi_col)` of the coded (prediction) block |
| 6463 | 6475 | /// covering that cell -- spec 7.14.2's `isBlockEdge`/libaom `pu_edge`, |
| 6464 | 6476 | /// which re-enables the loop filter at a prediction boundary between two |
| 6465 | 6477 | /// skipped inter blocks (lane-mergefix r4). Written by |
| 6466 | 6478 | /// [`Self::fill_skip_grid_rect`], whose `at_mi` IS that origin. |
| 6467 | - blk_org_grid: Vec<[u16; 2]>, | |
| 6468 | 6479 | /// Per-4x4-mi `(width, height)` in mi units of the coded block covering |
| 6469 | 6480 | /// that cell -- the other half of `pu_edge`: libaom tests the edge |
| 6470 | 6481 | /// coordinate against the block's size in the FILTERED plane's own |
| 6471 | 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 | 6484 | skip_grid_cols_mi: usize, |
| 6474 | 6485 | /// Per-4x4-mi luma transform width in pixels (8/16/32/64) -- this decoder |
| 6475 | 6486 | /// never splits a coded block's transform below its own size (round 2: |
| @@ -6591,10 +6602,10 @@ impl Neighbours { | ||
| 6591 | 6602 | left_filter: vec![[3u8; 2]; rows * (SUB / MI)], |
| 6592 | 6603 | mi_cols, |
| 6593 | 6604 | 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 | + ], | |
| 6598 | 6609 | skip_grid_cols_mi: cols * (SUB / MI), |
| 6599 | 6610 | tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], |
| 6600 | 6611 | tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], |
| @@ -7002,10 +7013,17 @@ impl Neighbours { | ||
| 7002 | 7013 | } |
| 7003 | 7014 | for rr in 0..h_mi { |
| 7004 | 7015 | 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 | + ); | |
| 7009 | 7027 | } |
| 7010 | 7028 | } |
| 7011 | 7029 | |
| @@ -7019,10 +7037,9 @@ impl Neighbours { | ||
| 7019 | 7037 | /// filter's `curr_skipped`/`pv_skip_txfm` (spec 7.14.2) want, since a |
| 7020 | 7038 | /// filtered edge's two sides are each exactly one coded block wide. |
| 7021 | 7039 | fn skip_at(&self, mi_r: usize, mi_c: usize) -> bool { |
| 7022 | - self.skip_grid | |
| 7040 | + self.blk_grid | |
| 7023 | 7041 | .get(mi_r * self.skip_grid_cols_mi + mi_c) |
| 7024 | - .copied() | |
| 7025 | - .unwrap_or(false) | |
| 7042 | + .is_some_and(|c| c.skip) | |
| 7026 | 7043 | } |
| 7027 | 7044 | |
| 7028 | 7045 | /// The `skip_txfm` context of a block whose top-left mi cell is |
| @@ -7038,10 +7055,9 @@ impl Neighbours { | ||
| 7038 | 7055 | fn is_skip_txfm(&self, mi_r: usize, mi_c: usize) -> bool { |
| 7039 | 7056 | (0..2).all(|rr| { |
| 7040 | 7057 | (0..2).all(|cc| { |
| 7041 | - self.skip_grid | |
| 7058 | + self.blk_grid | |
| 7042 | 7059 | .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) | |
| 7045 | 7061 | }) |
| 7046 | 7062 | }) |
| 7047 | 7063 | } |
| @@ -7293,19 +7309,21 @@ impl Neighbours { | ||
| 7293 | 7309 | /// units, for the same reason [`Self::record_mi`] does. |
| 7294 | 7310 | fn around_mi(&self, (mi_r, mi_c): (usize, usize), side: usize) -> [(bool, bool, i32); 3] { |
| 7295 | 7311 | 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 | |
| 7309 | 7327 | } |
| 7310 | 7328 | |
| 7311 | 7329 | /// [`Self::around`] with independent above (`w`)/left (`h`) extents, in |
| @@ -7319,21 +7337,25 @@ impl Neighbours { | ||
| 7319 | 7337 | /// mode-info units, mirroring [`Self::around_mi`]. |
| 7320 | 7338 | fn around_mi_rect(&self, (mi_r, mi_c): (usize, usize), w: usize, h: usize) -> [(bool, bool, i32); 3] { |
| 7321 | 7339 | 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); | |
| 7330 | 7347 | } |
| 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); | |
| 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 | 7359 | let ab: Vec<String> = (0..w_mi) |
| 7338 | 7360 | .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level)) |
| 7339 | 7361 | .collect(); |
| @@ -7342,8 +7364,8 @@ impl Neighbours { | ||
| 7342 | 7364 | .collect(); |
| 7343 | 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) | |
| 7346 | - }) | |
| 7367 | + } | |
| 7368 | + out | |
| 7347 | 7369 | } |
| 7348 | 7370 | |
| 7349 | 7371 | /// The luma `txb_skip_ctx` of a transform unit smaller than its own block |
| @@ -18056,8 +18078,8 @@ fn edge_params_body( | ||
| 18056 | 18078 | // bottom/right mi does not start there. Comparing mi origins instead is |
| 18057 | 18079 | // the same test only while the block's own origin is aligned to its |
| 18058 | 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]; | |
| 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); | |
| 18061 | 18083 | let (org_px, dim_mi) = if c.dir == 0 { |
| 18062 | 18084 | (usize::from(cur_org[1]), usize::from(cur_dim[0])) |
| 18063 | 18085 | } else { |
| @@ -19376,10 +19398,9 @@ fn apply_cdef( | ||
| 19376 | 19398 | if (0..2).any(|rr| { |
| 19377 | 19399 | (0..2).any(|cc| { |
| 19378 | 19400 | !skip_grid |
| 19379 | - .skip_written | |
| 19401 | + .blk_grid | |
| 19380 | 19402 | .get((r + rr) * skip_grid.skip_grid_cols_mi + (c + cc)) |
| 19381 | - .copied() | |
| 19382 | - .unwrap_or(true) | |
| 19403 | + .map_or(true, |x| x.written) | |
| 19383 | 19404 | }) |
| 19384 | 19405 | }) { |
| 19385 | 19406 | CDEF_UNWRITTEN_SKIP_UNITS.with(|c2| c2.set(c2.get() + 1)); |
| @@ -19389,10 +19410,9 @@ fn apply_cdef( | ||
| 19389 | 19410 | } |
| 19390 | 19411 | let cell = |rr: usize, cc: usize| { |
| 19391 | 19412 | skip_grid |
| 19392 | - .skip_grid | |
| 19413 | + .blk_grid | |
| 19393 | 19414 | .get((r + rr) * skip_grid.skip_grid_cols_mi + (c + cc)) |
| 19394 | - .copied() | |
| 19395 | - .unwrap_or(false) | |
| 19415 | + .is_some_and(|x| x.skip) | |
| 19396 | 19416 | }; |
| 19397 | 19417 | let first = cell(0, 0); |
| 19398 | 19418 | if (0..2).any(|rr| (0..2).any(|cc| cell(rr, cc) != first)) { |