Settle an all-zero transform block before the scan-order search
Browse files at this commitc3d93a7072e80ad87f099738ac0ec37d0bbd31a7Parent: 02bd8ae- perf
- settle an all-zero transform block before the scan-order search
1 changed file +13 -4
- crates/ec-av1/src/tile.rs +13 -4
crates/ec-av1/src/tile.rsmodified+13 -4
| @@ -2266,10 +2266,19 @@ fn write_coeffs( | ||
| 2266 | 2266 | ec_rng_trace(|| format!("EC_PLANE plane={plane} tell_before={}", enc.tell())); |
| 2267 | 2267 | } |
| 2268 | 2268 | let side = coding.side; |
| 2269 | - let eob = scan | |
| 2270 | - .iter() | |
| 2271 | - .rposition(|&pos| grid[pos as usize] != 0) | |
| 2272 | - .map_or(0, |i| i + 1); | |
| 2269 | + // The scan-order search reads the grid in scan order, one dependent load | |
| 2270 | + // per position, and an all-zero block makes it walk every one of them -- | |
| 2271 | + // which the pricer does for candidate after candidate. A straight-line | |
| 2272 | + // pass settles that case first: it vectorises, and a block that codes | |
| 2273 | + // anything at all almost always codes its DC, so it stops at the first | |
| 2274 | + // element. | |
| 2275 | + let eob = if grid.iter().all(|&level| level == 0) { | |
| 2276 | + 0 | |
| 2277 | + } else { | |
| 2278 | + scan.iter() | |
| 2279 | + .rposition(|&pos| grid[pos as usize] != 0) | |
| 2280 | + .map_or(0, |i| i + 1) | |
| 2281 | + }; | |
| 2273 | 2282 | enc.symbol(usize::from(eob == 0), &mut coding.txb_skip[skip_ctx]); |
| 2274 | 2283 | if plane.is_some() { |
| 2275 | 2284 | ec_rng_trace(|| { |