wip(av1): tile-boundary availability groundwork for multi-tile decode
Browse files at this commit4057ddad3601c47961e864abd4afeaf2af0e5e33Parent: 994cca71 changed file +57 -8
- crates/ec-av1/src/decode.rs +57 -8
crates/ec-av1/src/decode.rsmodified+57 -8
| @@ -1329,6 +1329,15 @@ struct Neighbours { | |||
| 1329 | /// widened from a bare `is_inter` bool, which collapsed every non-`LAST` | 1329 | /// widened from a bare `is_inter` bool, which collapsed every non-`LAST` |
| 1330 | /// reference onto `LAST_FRAME`'s own delta). | 1330 | /// reference onto `LAST_FRAME`'s own delta). |
| 1331 | ref_grid: Vec<i8>, | 1331 | ref_grid: Vec<i8>, |
| 1332 | + /// This tile's own top-left corner, in 4x4 mode-info units (spec | ||
| 1333 | + /// `MiRowStart`/`MiColStart`) -- lane-tiles: every "is there really a | ||
| 1334 | + /// neighbour" check compares against this instead of literal `0`, since a | ||
| 1335 | + /// block at the tile's own top/left edge has no usable neighbour even | ||
| 1336 | + /// though a decoded block sits there in the picture (spec `decode_tile`'s | ||
| 1337 | + /// per-tile `clear_above_context`/`left_available`/`up_available`). | ||
| 1338 | + /// `0` for a single-tile frame, matching every existing caller exactly. | ||
| 1339 | + tile_row0_mi: usize, | ||
| 1340 | + tile_col0_mi: usize, | ||
| 1332 | } | 1341 | } |
| 1333 | 1342 | ||
| 1334 | impl Neighbours { | 1343 | impl Neighbours { |
| @@ -1367,6 +1376,40 @@ impl Neighbours { | |||
| 1367 | tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], | 1376 | tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], |
| 1368 | tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], | 1377 | tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], |
| 1369 | ref_grid: vec![0i8; cols * (SUB / MI) * rows * (SUB / MI)], | 1378 | ref_grid: vec![0i8; cols * (SUB / MI) * rows * (SUB / MI)], |
| 1379 | + tile_row0_mi: 0, | ||
| 1380 | + tile_col0_mi: 0, | ||
| 1381 | + } | ||
| 1382 | + } | ||
| 1383 | + | ||
| 1384 | + /// spec `decode_tile`'s per-tile reset: `clear_above_context` over this | ||
| 1385 | + /// tile's own column span (`col1_mi` exclusive), plus recording | ||
| 1386 | + /// `(row0_mi, col0_mi)` as the tile's own top-left mi cell for every | ||
| 1387 | + /// availability check below. Left context resets every superblock row | ||
| 1388 | + /// regardless of tile ([`Self::start_row`], already called once per SB | ||
| 1389 | + /// row by every caller) so it needs no tile-specific reset here. | ||
| 1390 | + fn start_tile(&mut self, row0_mi: usize, col0_mi: usize, col1_mi: usize) { | ||
| 1391 | + self.tile_row0_mi = row0_mi; | ||
| 1392 | + self.tile_col0_mi = col0_mi; | ||
| 1393 | + let end = col1_mi.min(self.above.len()); | ||
| 1394 | + for i in col0_mi.min(end)..end { | ||
| 1395 | + self.above[i] = Default::default(); | ||
| 1396 | + self.above_side_mi[i] = SB; | ||
| 1397 | + } | ||
| 1398 | + let (sc0, sc1) = ( | ||
| 1399 | + col0_mi / (SUB / MI), | ||
| 1400 | + (col1_mi / (SUB / MI)).min(self.above_mode.len()), | ||
| 1401 | + ); | ||
| 1402 | + for i in sc0.min(sc1)..sc1 { | ||
| 1403 | + self.above_mode[i] = DC_PRED; | ||
| 1404 | + self.above_side[i] = SB; | ||
| 1405 | + self.above_skip[i] = false; | ||
| 1406 | + self.above_skip_mode[i] = false; | ||
| 1407 | + self.above_inter[i] = false; | ||
| 1408 | + self.above_ref[i] = -1; | ||
| 1409 | + self.above_ref1[i] = None; | ||
| 1410 | + self.above_comp_group_idx[i] = 0; | ||
| 1411 | + self.above_compound_idx[i] = 0; | ||
| 1412 | + self.above_filter[i] = [3u8; 2]; | ||
| 1370 | } | 1413 | } |
| 1371 | } | 1414 | } |
| 1372 | 1415 | ||
| @@ -1455,8 +1498,8 @@ impl Neighbours { | |||
| 1455 | /// with an absent neighbour contributing 0. The mi grid is per tile, so | 1498 | /// with an absent neighbour contributing 0. The mi grid is per tile, so |
| 1456 | /// row/column 0 is a tile edge and has no neighbour on that axis. | 1499 | /// row/column 0 is a tile edge and has no neighbour on that axis. |
| 1457 | fn skip_txfm_ctx(&self, mi_r: usize, mi_c: usize) -> usize { | 1500 | fn skip_txfm_ctx(&self, mi_r: usize, mi_c: usize) -> usize { |
| 1458 | - usize::from(mi_r > 0 && self.skip_at(mi_r - 1, mi_c)) | 1501 | + usize::from(mi_r > self.tile_row0_mi && self.skip_at(mi_r - 1, mi_c)) |
| 1459 | - + usize::from(mi_c > 0 && self.skip_at(mi_r, mi_c - 1)) | 1502 | + + usize::from(mi_c > self.tile_col0_mi && self.skip_at(mi_r, mi_c - 1)) |
| 1460 | } | 1503 | } |
| 1461 | 1504 | ||
| 1462 | fn is_skip_txfm(&self, mi_r: usize, mi_c: usize) -> bool { | 1505 | fn is_skip_txfm(&self, mi_r: usize, mi_c: usize) -> bool { |
| @@ -2021,8 +2064,8 @@ fn tx_size_context_rect( | |||
| 2021 | own_w: usize, | 2064 | own_w: usize, |
| 2022 | own_h: usize, | 2065 | own_h: usize, |
| 2023 | ) -> usize { | 2066 | ) -> usize { |
| 2024 | - let above = mi_r > 0 && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w; | 2067 | + let above = mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w; |
| 2025 | - let left = mi_c > 0 && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h; | 2068 | + let left = mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h; |
| 2026 | usize::from(above) + usize::from(left) | 2069 | usize::from(above) + usize::from(left) |
| 2027 | } | 2070 | } |
| 2028 | 2071 | ||
| @@ -3808,8 +3851,8 @@ fn tx_h_px_at(n: &Neighbours, chroma: bool, mi_r: usize, mi_c: usize) -> u32 { | |||
| 3808 | /// to the left (at its own topmost mi row) coded a transform at least as wide | 3851 | /// to the left (at its own topmost mi row) coded a transform at least as wide |
| 3809 | /// as `own_side`. | 3852 | /// as `own_side`. |
| 3810 | fn tx_size_context(n: &Neighbours, (mi_r, mi_c): (usize, usize), own_side: usize) -> usize { | 3853 | fn tx_size_context(n: &Neighbours, (mi_r, mi_c): (usize, usize), own_side: usize) -> usize { |
| 3811 | - let above = mi_r > 0 && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_side; | 3854 | + let above = mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_side; |
| 3812 | - let left = mi_c > 0 && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_side; | 3855 | + let left = mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_side; |
| 3813 | usize::from(above) + usize::from(left) | 3856 | usize::from(above) + usize::from(left) |
| 3814 | } | 3857 | } |
| 3815 | 3858 | ||
| @@ -6387,7 +6430,10 @@ fn decode_inter_block( | |||
| 6387 | )); | 6430 | )); |
| 6388 | } | 6431 | } |
| 6389 | 6432 | ||
| 6390 | - let (has_above, has_left) = (r > 0, c > 0); | 6433 | + let (has_above, has_left) = ( |
| 6434 | + r > neighbours.tile_row0_mi / (SUB / MI), | ||
| 6435 | + c > neighbours.tile_col0_mi / (SUB / MI), | ||
| 6436 | + ); | ||
| 6391 | let (above_inter, left_inter) = (neighbours.above_inter[c], neighbours.left_inter[r]); | 6437 | let (above_inter, left_inter) = (neighbours.above_inter[c], neighbours.left_inter[r]); |
| 6392 | let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); | 6438 | let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); |
| 6393 | let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; | 6439 | let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; |
| @@ -8106,7 +8152,10 @@ fn decode_inter_block8( | |||
| 8106 | let skip_ctx = usize::from(above_skip) + usize::from(left_skip); | 8152 | let skip_ctx = usize::from(above_skip) + usize::from(left_skip); |
| 8107 | let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; | 8153 | let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; |
| 8108 | 8154 | ||
| 8109 | - let (has_above, has_left) = (leaf_mi.0 > 0, leaf_mi.1 > 0); | 8155 | + let (has_above, has_left) = ( |
| 8156 | + leaf_mi.0 > neighbours.tile_row0_mi, | ||
| 8157 | + leaf_mi.1 > neighbours.tile_col0_mi, | ||
| 8158 | + ); | ||
| 8110 | let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); | 8159 | let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); |
| 8111 | let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; | 8160 | let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; |
| 8112 | 8161 | ||