Merge branch 'lane-tiles': key frames with two tile columns decode
Browse files at this commit10 changed files +1141 -37
- crates/ec-av1/src/decode.rs +194 -30
- crates/ec-av1/src/refusal_inventory.rs +4 -1
- crates/ec-av1/src/stream.rs +428 -6
- lanes/tiles-r2.charter.md +61 -0
- lanes/tiles-r3.charter.md +48 -0
- lanes/tiles-r3.report.md +67 -0
- lanes/tiles-r4.charter.md +47 -0
- lanes/tiles-r4.report.md +80 -0
- lanes/tiles.charter.md +96 -0
- lanes/tiles.report.md +116 -0
crates/ec-av1/src/decode.rsmodified+194 -30
| @@ -21,7 +21,7 @@ | |||
| 21 | //! too). Anything outside that refuses with [`Error::unsupported`] rather than | 21 | //! too). Anything outside that refuses with [`Error::unsupported`] rather than |
| 22 | //! silently miscoding. | 22 | //! silently miscoding. |
| 23 | 23 | ||
| 24 | -use ec_av1_syntax::{CdefParams, LoopFilterParams}; | 24 | +use ec_av1_syntax::{CdefParams, LoopFilterParams, TileInfo}; |
| 25 | use ec_core::{Error, Result}; | 25 | use ec_core::{Error, Result}; |
| 26 | 26 | ||
| 27 | use crate::cdf; | 27 | use crate::cdf; |
| @@ -163,6 +163,20 @@ pub(crate) fn smooth_uv_hits() -> usize { | |||
| 163 | SMOOTH_UV_HITS.with(|c| c.get()) | 163 | SMOOTH_UV_HITS.with(|c| c.get()) |
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | +// How many tiles [`decode_key_frame_tile_with_cdfs`] has actually decoded a | ||
| 167 | +// full superblock walk over, across every call on the current thread -- | ||
| 168 | +// lane-tiles r2's own gate-blind-to-feature guard: a gate over a | ||
| 169 | +// multi-tile stream must prove more than one tile actually fired, not just | ||
| 170 | +// that the stream carried tile_info.cols > 1. | ||
| 171 | +thread_local! { | ||
| 172 | + static TILE_HITS: std::cell::Cell<usize> = | ||
| 173 | + const { std::cell::Cell::new(0) }; | ||
| 174 | +} | ||
| 175 | +/// Current value of [`TILE_HITS`]. | ||
| 176 | +pub(crate) fn tile_hits() -> usize { | ||
| 177 | + TILE_HITS.with(|c| c.get()) | ||
| 178 | +} | ||
| 179 | + | ||
| 166 | // How many 4-pixel deblocking edge groups [`edge_params`] has actually | 180 | // How many 4-pixel deblocking edge groups [`edge_params`] has actually |
| 167 | // selected for filtering, across every call on the current thread -- the same | 181 | // selected for filtering, across every call on the current thread -- the same |
| 168 | // before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream | 182 | // before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream |
| @@ -1444,6 +1458,15 @@ struct Neighbours { | |||
| 1444 | /// widened from a bare `is_inter` bool, which collapsed every non-`LAST` | 1458 | /// widened from a bare `is_inter` bool, which collapsed every non-`LAST` |
| 1445 | /// reference onto `LAST_FRAME`'s own delta). | 1459 | /// reference onto `LAST_FRAME`'s own delta). |
| 1446 | ref_grid: Vec<i8>, | 1460 | ref_grid: Vec<i8>, |
| 1461 | + /// This tile's own top-left corner, in 4x4 mode-info units (spec | ||
| 1462 | + /// `MiRowStart`/`MiColStart`) -- lane-tiles: every "is there really a | ||
| 1463 | + /// neighbour" check compares against this instead of literal `0`, since a | ||
| 1464 | + /// block at the tile's own top/left edge has no usable neighbour even | ||
| 1465 | + /// though a decoded block sits there in the picture (spec `decode_tile`'s | ||
| 1466 | + /// per-tile `clear_above_context`/`left_available`/`up_available`). | ||
| 1467 | + /// `0` for a single-tile frame, matching every existing caller exactly. | ||
| 1468 | + tile_row0_mi: usize, | ||
| 1469 | + tile_col0_mi: usize, | ||
| 1447 | } | 1470 | } |
| 1448 | 1471 | ||
| 1449 | impl Neighbours { | 1472 | impl Neighbours { |
| @@ -1484,6 +1507,40 @@ impl Neighbours { | |||
| 1484 | tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], | 1507 | tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], |
| 1485 | tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], | 1508 | tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], |
| 1486 | ref_grid: vec![0i8; cols * (SUB / MI) * rows * (SUB / MI)], | 1509 | ref_grid: vec![0i8; cols * (SUB / MI) * rows * (SUB / MI)], |
| 1510 | + tile_row0_mi: 0, | ||
| 1511 | + tile_col0_mi: 0, | ||
| 1512 | + } | ||
| 1513 | + } | ||
| 1514 | + | ||
| 1515 | + /// spec `decode_tile`'s per-tile reset: `clear_above_context` over this | ||
| 1516 | + /// tile's own column span (`col1_mi` exclusive), plus recording | ||
| 1517 | + /// `(row0_mi, col0_mi)` as the tile's own top-left mi cell for every | ||
| 1518 | + /// availability check below. Left context resets every superblock row | ||
| 1519 | + /// regardless of tile ([`Self::start_row`], already called once per SB | ||
| 1520 | + /// row by every caller) so it needs no tile-specific reset here. | ||
| 1521 | + fn start_tile(&mut self, row0_mi: usize, col0_mi: usize, col1_mi: usize) { | ||
| 1522 | + self.tile_row0_mi = row0_mi; | ||
| 1523 | + self.tile_col0_mi = col0_mi; | ||
| 1524 | + let end = col1_mi.min(self.above.len()); | ||
| 1525 | + for i in col0_mi.min(end)..end { | ||
| 1526 | + self.above[i] = Default::default(); | ||
| 1527 | + self.above_side_mi[i] = SB; | ||
| 1528 | + } | ||
| 1529 | + let (sc0, sc1) = ( | ||
| 1530 | + col0_mi / (SUB / MI), | ||
| 1531 | + (col1_mi / (SUB / MI)).min(self.above_mode.len()), | ||
| 1532 | + ); | ||
| 1533 | + for i in sc0.min(sc1)..sc1 { | ||
| 1534 | + self.above_mode[i] = DC_PRED; | ||
| 1535 | + self.above_side[i] = SB; | ||
| 1536 | + self.above_skip[i] = false; | ||
| 1537 | + self.above_skip_mode[i] = false; | ||
| 1538 | + self.above_inter[i] = false; | ||
| 1539 | + self.above_ref[i] = -1; | ||
| 1540 | + self.above_ref1[i] = None; | ||
| 1541 | + self.above_comp_group_idx[i] = 0; | ||
| 1542 | + self.above_compound_idx[i] = 0; | ||
| 1543 | + self.above_filter[i] = [3u8; 2]; | ||
| 1487 | } | 1544 | } |
| 1488 | } | 1545 | } |
| 1489 | 1546 | ||
| @@ -1572,8 +1629,8 @@ impl Neighbours { | |||
| 1572 | /// with an absent neighbour contributing 0. The mi grid is per tile, so | 1629 | /// with an absent neighbour contributing 0. The mi grid is per tile, so |
| 1573 | /// row/column 0 is a tile edge and has no neighbour on that axis. | 1630 | /// row/column 0 is a tile edge and has no neighbour on that axis. |
| 1574 | fn skip_txfm_ctx(&self, mi_r: usize, mi_c: usize) -> usize { | 1631 | fn skip_txfm_ctx(&self, mi_r: usize, mi_c: usize) -> usize { |
| 1575 | - usize::from(mi_r > 0 && self.skip_at(mi_r - 1, mi_c)) | 1632 | + usize::from(mi_r > self.tile_row0_mi && self.skip_at(mi_r - 1, mi_c)) |
| 1576 | - + usize::from(mi_c > 0 && self.skip_at(mi_r, mi_c - 1)) | 1633 | + + usize::from(mi_c > self.tile_col0_mi && self.skip_at(mi_r, mi_c - 1)) |
| 1577 | } | 1634 | } |
| 1578 | 1635 | ||
| 1579 | fn is_skip_txfm(&self, mi_r: usize, mi_c: usize) -> bool { | 1636 | fn is_skip_txfm(&self, mi_r: usize, mi_c: usize) -> bool { |
| @@ -2155,8 +2212,8 @@ fn tx_size_context_rect( | |||
| 2155 | own_w: usize, | 2212 | own_w: usize, |
| 2156 | own_h: usize, | 2213 | own_h: usize, |
| 2157 | ) -> usize { | 2214 | ) -> usize { |
| 2158 | - let above = mi_r > 0 && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w; | 2215 | + let above = mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w; |
| 2159 | - let left = mi_c > 0 && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h; | 2216 | + let left = mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h; |
| 2160 | usize::from(above) + usize::from(left) | 2217 | usize::from(above) + usize::from(left) |
| 2161 | } | 2218 | } |
| 2162 | 2219 | ||
| @@ -2777,6 +2834,16 @@ struct PlaneBuf { | |||
| 2777 | /// real decoder's edge or reach reads. | 2834 | /// real decoder's edge or reach reads. |
| 2778 | true_width: usize, | 2835 | true_width: usize, |
| 2779 | true_height: usize, | 2836 | true_height: usize, |
| 2837 | + /// This plane's own tile's top-left pixel origin (spec: intra prediction | ||
| 2838 | + /// never reaches across a tile boundary even though an earlier-decoded | ||
| 2839 | + /// tile's real pixels sit right there in the shared buffer) — set via | ||
| 2840 | + /// [`Self::set_tile_origin`] before each tile's own superblock walk, | ||
| 2841 | + /// `0` for the single-tile case. lane-tiles r2: only the left/top bound | ||
| 2842 | + /// is threaded (the two-tile column-split stage 1 fixture's tile always | ||
| 2843 | + /// ends at the frame's own right/bottom edge); a non-last tile's own | ||
| 2844 | + /// right/bottom reach bound is still open, tracked in the report. | ||
| 2845 | + tile_x0: usize, | ||
| 2846 | + tile_y0: usize, | ||
| 2780 | } | 2847 | } |
| 2781 | 2848 | ||
| 2782 | /// One entry per `MV_REFERENCE_FRAME` (index 0/1 unused -- `NONE`/ | 2849 | /// One entry per `MV_REFERENCE_FRAME` (index 0/1 unused -- `NONE`/ |
| @@ -2788,6 +2855,15 @@ struct PlaneBuf { | |||
| 2788 | type RefSlots<'a> = [Option<(&'a PlaneBuf, &'a PlaneBuf, &'a PlaneBuf)>; 8]; | 2855 | type RefSlots<'a> = [Option<(&'a PlaneBuf, &'a PlaneBuf, &'a PlaneBuf)>; 8]; |
| 2789 | 2856 | ||
| 2790 | impl PlaneBuf { | 2857 | impl PlaneBuf { |
| 2858 | + /// Sets this plane's own tile pixel origin ([`Self::tile_x0`]/ | ||
| 2859 | + /// [`Self::tile_y0`]) before that tile's own superblock walk. `x0`/`y0` | ||
| 2860 | + /// are already in this plane's own units (luma pixels for `y`, chroma | ||
| 2861 | + /// pixels — halved — for `u`/`v`). | ||
| 2862 | + fn set_tile_origin(&mut self, x0: usize, y0: usize) { | ||
| 2863 | + self.tile_x0 = x0; | ||
| 2864 | + self.tile_y0 = y0; | ||
| 2865 | + } | ||
| 2866 | + | ||
| 2791 | fn edges( | 2867 | fn edges( |
| 2792 | &self, | 2868 | &self, |
| 2793 | x: usize, | 2869 | x: usize, |
| @@ -2809,14 +2885,15 @@ impl PlaneBuf { | |||
| 2809 | own_down | 2885 | own_down |
| 2810 | } | 2886 | } |
| 2811 | .min(self.height); | 2887 | .min(self.height); |
| 2812 | - let above = (y > 0 && across > x) | 2888 | + let above = (y > self.tile_y0 && across > x) |
| 2813 | .then(|| self.data[(y - 1) * self.width + x..][..across - x].to_vec()); | 2889 | .then(|| self.data[(y - 1) * self.width + x..][..across - x].to_vec()); |
| 2814 | - let left = (x > 0 && down > y).then(|| { | 2890 | + let left = (x > self.tile_x0 && down > y).then(|| { |
| 2815 | (y..down) | 2891 | (y..down) |
| 2816 | .map(|row| self.data[row * self.width + x - 1]) | 2892 | .map(|row| self.data[row * self.width + x - 1]) |
| 2817 | .collect::<Vec<_>>() | 2893 | .collect::<Vec<_>>() |
| 2818 | }); | 2894 | }); |
| 2819 | - let corner = (x > 0 && y > 0).then(|| self.data[(y - 1) * self.width + x - 1]); | 2895 | + let corner = |
| 2896 | + (x > self.tile_x0 && y > self.tile_y0).then(|| self.data[(y - 1) * self.width + x - 1]); | ||
| 2820 | (above, left, corner) | 2897 | (above, left, corner) |
| 2821 | } | 2898 | } |
| 2822 | 2899 | ||
| @@ -2845,14 +2922,15 @@ impl PlaneBuf { | |||
| 2845 | own_down | 2922 | own_down |
| 2846 | } | 2923 | } |
| 2847 | .min(self.height); | 2924 | .min(self.height); |
| 2848 | - let above = (y > 0 && across > x) | 2925 | + let above = (y > self.tile_y0 && across > x) |
| 2849 | .then(|| self.data[(y - 1) * self.width + x..][..across - x].to_vec()); | 2926 | .then(|| self.data[(y - 1) * self.width + x..][..across - x].to_vec()); |
| 2850 | - let left = (x > 0 && down > y).then(|| { | 2927 | + let left = (x > self.tile_x0 && down > y).then(|| { |
| 2851 | (y..down) | 2928 | (y..down) |
| 2852 | .map(|row| self.data[row * self.width + x - 1]) | 2929 | .map(|row| self.data[row * self.width + x - 1]) |
| 2853 | .collect::<Vec<_>>() | 2930 | .collect::<Vec<_>>() |
| 2854 | }); | 2931 | }); |
| 2855 | - let corner = (x > 0 && y > 0).then(|| self.data[(y - 1) * self.width + x - 1]); | 2932 | + let corner = |
| 2933 | + (x > self.tile_x0 && y > self.tile_y0).then(|| self.data[(y - 1) * self.width + x - 1]); | ||
| 2856 | (above, left, corner) | 2934 | (above, left, corner) |
| 2857 | } | 2935 | } |
| 2858 | 2936 | ||
| @@ -4009,8 +4087,8 @@ fn tx_h_px_at(n: &Neighbours, chroma: bool, mi_r: usize, mi_c: usize) -> u32 { | |||
| 4009 | /// to the left (at its own topmost mi row) coded a transform at least as wide | 4087 | /// to the left (at its own topmost mi row) coded a transform at least as wide |
| 4010 | /// as `own_side`. | 4088 | /// as `own_side`. |
| 4011 | fn tx_size_context(n: &Neighbours, (mi_r, mi_c): (usize, usize), own_side: usize) -> usize { | 4089 | fn tx_size_context(n: &Neighbours, (mi_r, mi_c): (usize, usize), own_side: usize) -> usize { |
| 4012 | - let above = mi_r > 0 && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_side; | 4090 | + let above = mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_side; |
| 4013 | - let left = mi_c > 0 && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_side; | 4091 | + let left = mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_side; |
| 4014 | usize::from(above) + usize::from(left) | 4092 | usize::from(above) + usize::from(left) |
| 4015 | } | 4093 | } |
| 4016 | 4094 | ||
| @@ -4668,8 +4746,14 @@ pub fn decode_key_frame_tile( | |||
| 4668 | allow_screen_content_tools: bool, | 4746 | allow_screen_content_tools: bool, |
| 4669 | allow_intrabc: bool, | 4747 | allow_intrabc: bool, |
| 4670 | ) -> Result<Picture> { | 4748 | ) -> Result<Picture> { |
| 4749 | + let single_tile = TileInfo { | ||
| 4750 | + mi_col_starts: vec![0, mi_cols], | ||
| 4751 | + mi_row_starts: vec![0, mi_rows], | ||
| 4752 | + ..TileInfo::default() | ||
| 4753 | + }; | ||
| 4671 | decode_key_frame_tile_with_cdfs( | 4754 | decode_key_frame_tile_with_cdfs( |
| 4672 | - data, | 4755 | + &[data], |
| 4756 | + &single_tile, | ||
| 4673 | mi_cols, | 4757 | mi_cols, |
| 4674 | mi_rows, | 4758 | mi_rows, |
| 4675 | base_q_idx, | 4759 | base_q_idx, |
| @@ -4697,7 +4781,8 @@ pub fn decode_key_frame_tile( | |||
| 4697 | /// alongside the picture, for the caller to save into whichever reference | 4781 | /// alongside the picture, for the caller to save into whichever reference |
| 4698 | /// slots this frame's `refresh_frame_flags` names. | 4782 | /// slots this frame's `refresh_frame_flags` names. |
| 4699 | pub(crate) fn decode_key_frame_tile_with_cdfs( | 4783 | pub(crate) fn decode_key_frame_tile_with_cdfs( |
| 4700 | - data: &[u8], | 4784 | + tiles: &[&[u8]], |
| 4785 | + tile_info: &TileInfo, | ||
| 4701 | mi_cols: u32, | 4786 | mi_cols: u32, |
| 4702 | mi_rows: u32, | 4787 | mi_rows: u32, |
| 4703 | base_q_idx: u8, | 4788 | base_q_idx: u8, |
| @@ -4731,6 +4816,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4731 | height, | 4816 | height, |
| 4732 | true_width, | 4817 | true_width, |
| 4733 | true_height, | 4818 | true_height, |
| 4819 | + tile_x0: 0, | ||
| 4820 | + tile_y0: 0, | ||
| 4734 | }; | 4821 | }; |
| 4735 | let mut u = PlaneBuf { | 4822 | let mut u = PlaneBuf { |
| 4736 | data: vec![0u8; width * height / 4], | 4823 | data: vec![0u8; width * height / 4], |
| @@ -4738,6 +4825,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4738 | height: height / 2, | 4825 | height: height / 2, |
| 4739 | true_width: true_width / 2, | 4826 | true_width: true_width / 2, |
| 4740 | true_height: true_height / 2, | 4827 | true_height: true_height / 2, |
| 4828 | + tile_x0: 0, | ||
| 4829 | + tile_y0: 0, | ||
| 4741 | }; | 4830 | }; |
| 4742 | let mut v = PlaneBuf { | 4831 | let mut v = PlaneBuf { |
| 4743 | data: vec![0u8; width * height / 4], | 4832 | data: vec![0u8; width * height / 4], |
| @@ -4745,6 +4834,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4745 | height: height / 2, | 4834 | height: height / 2, |
| 4746 | true_width: true_width / 2, | 4835 | true_width: true_width / 2, |
| 4747 | true_height: true_height / 2, | 4836 | true_height: true_height / 2, |
| 4837 | + tile_x0: 0, | ||
| 4838 | + tile_y0: 0, | ||
| 4748 | }; | 4839 | }; |
| 4749 | 4840 | ||
| 4750 | let scan32 = default_scan(TX32); | 4841 | let scan32 = default_scan(TX32); |
| @@ -4752,15 +4843,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4752 | let scan8 = default_scan(TX8); | 4843 | let scan8 = default_scan(TX8); |
| 4753 | let scan4 = default_scan(TX4); | 4844 | let scan4 = default_scan(TX4); |
| 4754 | 4845 | ||
| 4755 | - let mut cdfs = initial_cdfs.unwrap_or_else(|| Cdfs::new(q_ctx_of(base_q_idx))); | 4846 | + let base_cdfs = initial_cdfs.unwrap_or_else(|| Cdfs::new(q_ctx_of(base_q_idx))); |
| 4756 | - if std::env::var_os("EC_AV1_TRACE").is_some() { | 4847 | + let mut result_cdfs = base_cdfs.clone(); |
| 4757 | - eprintln!( | ||
| 4758 | - "TRACE key_tile_bytes len={} first8={:02x?} base_q_idx={base_q_idx} mi_cols={mi_cols} mi_rows={mi_rows}", | ||
| 4759 | - data.len(), | ||
| 4760 | - &data[..data.len().min(8)] | ||
| 4761 | - ); | ||
| 4762 | - } | ||
| 4763 | - let mut dec = SymbolDecoder::new(data); | ||
| 4764 | let mut neighbours = Neighbours::new( | 4848 | let mut neighbours = Neighbours::new( |
| 4765 | cols32 as usize * 2, | 4849 | cols32 as usize * 2, |
| 4766 | rows32 as usize * 2, | 4850 | rows32 as usize * 2, |
| @@ -4768,9 +4852,50 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4768 | mi_rows as usize, | 4852 | mi_rows as usize, |
| 4769 | ); | 4853 | ); |
| 4770 | 4854 | ||
| 4771 | - for sb_r in 0..sb_rows { | 4855 | + // lane-tiles r2: each tile gets its own fresh `SymbolDecoder` over its |
| 4856 | + // own byte range and its own fresh copy of the frame's initial CDFs | ||
| 4857 | + // (spec 5.11.2 `decode_tile`'s `init_symbol`); only the tile named by | ||
| 4858 | + // `context_update_tile_id` has its end-of-tile adapted table kept as the | ||
| 4859 | + // frame's own output (spec `exit_symbol`) -- every other tile's | ||
| 4860 | + // adaptation is discarded, matching the refusal this replaces. | ||
| 4861 | + for (tile_idx, &tile_bytes) in tiles.iter().enumerate() { | ||
| 4862 | + let tile_num = tile_idx as u32; | ||
| 4863 | + let (trow, tcol) = (tile_num / tile_info.cols, tile_num % tile_info.cols); | ||
| 4864 | + let mi_row0 = tile_info.mi_row_starts[trow as usize]; | ||
| 4865 | + let mi_row1 = tile_info.mi_row_starts[trow as usize + 1]; | ||
| 4866 | + let mi_col0 = tile_info.mi_col_starts[tcol as usize]; | ||
| 4867 | + let mi_col1 = tile_info.mi_col_starts[tcol as usize + 1]; | ||
| 4868 | + // Tile boundaries are always superblock-aligned in mi units (spec | ||
| 4869 | + // 5.9.15's uniform/non-uniform derivation both only ever emit | ||
| 4870 | + // multiples of the superblock's own mi size), so plain division is | ||
| 4871 | + // exact here -- no rounding needed. | ||
| 4872 | + // `mi_row0`/`mi_col0` (this tile's own start, `0` or an interior | ||
| 4873 | + // tile boundary) are always superblock-aligned by spec 5.9.15; the | ||
| 4874 | + // frame's own true final edge (`mi_row_starts`/`mi_col_starts`' | ||
| 4875 | + // last entry) is not, so the upper bound needs `div_ceil` the same | ||
| 4876 | + // way the whole-frame `sb_rows`/`sb_cols` above does, to keep the | ||
| 4877 | + // trailing partial superblock row/column in scope. | ||
| 4878 | + let (sb_r0, sb_r1) = ((mi_row0 / SB_MI).min(sb_rows), mi_row1.div_ceil(SB_MI).min(sb_rows)); | ||
| 4879 | + let (sb_c0, sb_c1) = ((mi_col0 / SB_MI).min(sb_cols), mi_col1.div_ceil(SB_MI).min(sb_cols)); | ||
| 4880 | + | ||
| 4881 | + let mut cdfs = base_cdfs.clone(); | ||
| 4882 | + if std::env::var_os("EC_AV1_TRACE").is_some() { | ||
| 4883 | + eprintln!( | ||
| 4884 | + "TRACE key_tile_bytes tile={tile_num} len={} first8={:02x?} base_q_idx={base_q_idx} mi_cols={mi_cols} mi_rows={mi_rows}", | ||
| 4885 | + tile_bytes.len(), | ||
| 4886 | + &tile_bytes[..tile_bytes.len().min(8)] | ||
| 4887 | + ); | ||
| 4888 | + } | ||
| 4889 | + let mut dec = SymbolDecoder::new(tile_bytes); | ||
| 4890 | + neighbours.start_tile(mi_row0 as usize, mi_col0 as usize, mi_col1 as usize); | ||
| 4891 | + y.set_tile_origin(mi_col0 as usize * 4, mi_row0 as usize * 4); | ||
| 4892 | + u.set_tile_origin(mi_col0 as usize * 2, mi_row0 as usize * 2); | ||
| 4893 | + v.set_tile_origin(mi_col0 as usize * 2, mi_row0 as usize * 2); | ||
| 4894 | + TILE_HITS.with(|c| c.set(c.get() + 1)); | ||
| 4895 | + | ||
| 4896 | + for sb_r in sb_r0..sb_r1 { | ||
| 4772 | neighbours.start_row(); | 4897 | neighbours.start_row(); |
| 4773 | - for sb_c in 0..sb_cols { | 4898 | + for sb_c in sb_c0..sb_c1 { |
| 4774 | CDEF_TRANSMITTED.with(|c| c.set(false)); | 4899 | CDEF_TRANSMITTED.with(|c| c.set(false)); |
| 4775 | let at = (sb_r as usize * 4, sb_c as usize * 4); | 4900 | let at = (sb_r as usize * 4, sb_c as usize * 4); |
| 4776 | let ctx = neighbours.partition_ctx(at, SB); | 4901 | let ctx = neighbours.partition_ctx(at, SB); |
| @@ -5171,6 +5296,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 5171 | } | 5296 | } |
| 5172 | } | 5297 | } |
| 5173 | 5298 | ||
| 5299 | + if tile_num == tile_info.context_update_tile_id { | ||
| 5300 | + result_cdfs = cdfs; | ||
| 5301 | + } | ||
| 5302 | + } | ||
| 5303 | + | ||
| 5174 | // lane-comppin r4: pre-loop-filter decode-order dump, matching aomdec's | 5304 | // lane-comppin r4: pre-loop-filter decode-order dump, matching aomdec's |
| 5175 | // own EC_AV1_PREFILT_DUMP shape (decodeframe.c ~5451) -- diffs against | 5305 | // own EC_AV1_PREFILT_DUMP shape (decodeframe.c ~5451) -- diffs against |
| 5176 | // that isolate whether a decode-order frame's mismatch already exists | 5306 | // that isolate whether a decode-order frame's mismatch already exists |
| @@ -5200,7 +5330,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 5200 | u: u.data, | 5330 | u: u.data, |
| 5201 | v: v.data, | 5331 | v: v.data, |
| 5202 | }, | 5332 | }, |
| 5203 | - cdfs, | 5333 | + result_cdfs, |
| 5204 | )); | 5334 | )); |
| 5205 | } | 5335 | } |
| 5206 | let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u8> { | 5336 | let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u8> { |
| @@ -5218,7 +5348,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 5218 | u: crop(&u, fw / 2, fh / 2), | 5348 | u: crop(&u, fw / 2, fh / 2), |
| 5219 | v: crop(&v, fw / 2, fh / 2), | 5349 | v: crop(&v, fw / 2, fh / 2), |
| 5220 | }, | 5350 | }, |
| 5221 | - cdfs, | 5351 | + result_cdfs, |
| 5222 | )) | 5352 | )) |
| 5223 | } | 5353 | } |
| 5224 | 5354 | ||
| @@ -6613,7 +6743,10 @@ fn decode_inter_block( | |||
| 6613 | )); | 6743 | )); |
| 6614 | } | 6744 | } |
| 6615 | 6745 | ||
| 6616 | - let (has_above, has_left) = (r > 0, c > 0); | 6746 | + let (has_above, has_left) = ( |
| 6747 | + r > neighbours.tile_row0_mi / (SUB / MI), | ||
| 6748 | + c > neighbours.tile_col0_mi / (SUB / MI), | ||
| 6749 | + ); | ||
| 6617 | let (above_inter, left_inter) = (neighbours.above_inter[c], neighbours.left_inter[r]); | 6750 | let (above_inter, left_inter) = (neighbours.above_inter[c], neighbours.left_inter[r]); |
| 6618 | let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); | 6751 | let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); |
| 6619 | let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; | 6752 | let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; |
| @@ -8372,7 +8505,10 @@ fn decode_inter_block8( | |||
| 8372 | let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; | 8505 | let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; |
| 8373 | maybe_read_cdef_idx(dec, leaf_mi.0, leaf_mi.1, skip); | 8506 | maybe_read_cdef_idx(dec, leaf_mi.0, leaf_mi.1, skip); |
| 8374 | 8507 | ||
| 8375 | - let (has_above, has_left) = (leaf_mi.0 > 0, leaf_mi.1 > 0); | 8508 | + let (has_above, has_left) = ( |
| 8509 | + leaf_mi.0 > neighbours.tile_row0_mi, | ||
| 8510 | + leaf_mi.1 > neighbours.tile_col0_mi, | ||
| 8511 | + ); | ||
| 8376 | let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); | 8512 | let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); |
| 8377 | let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; | 8513 | let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; |
| 8378 | 8514 | ||
| @@ -9446,6 +9582,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 9446 | height: reference.height, | 9582 | height: reference.height, |
| 9447 | true_width: reference.width, | 9583 | true_width: reference.width, |
| 9448 | true_height: reference.height, | 9584 | true_height: reference.height, |
| 9585 | + tile_x0: 0, | ||
| 9586 | + tile_y0: 0, | ||
| 9449 | }; | 9587 | }; |
| 9450 | let ref_u = PlaneBuf { | 9588 | let ref_u = PlaneBuf { |
| 9451 | data: reference.u.clone(), | 9589 | data: reference.u.clone(), |
| @@ -9453,6 +9591,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 9453 | height: reference.height / 2, | 9591 | height: reference.height / 2, |
| 9454 | true_width: reference.width / 2, | 9592 | true_width: reference.width / 2, |
| 9455 | true_height: reference.height / 2, | 9593 | true_height: reference.height / 2, |
| 9594 | + tile_x0: 0, | ||
| 9595 | + tile_y0: 0, | ||
| 9456 | }; | 9596 | }; |
| 9457 | let ref_v = PlaneBuf { | 9597 | let ref_v = PlaneBuf { |
| 9458 | data: reference.v.clone(), | 9598 | data: reference.v.clone(), |
| @@ -9460,6 +9600,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 9460 | height: reference.height / 2, | 9600 | height: reference.height / 2, |
| 9461 | true_width: reference.width / 2, | 9601 | true_width: reference.width / 2, |
| 9462 | true_height: reference.height / 2, | 9602 | true_height: reference.height / 2, |
| 9603 | + tile_x0: 0, | ||
| 9604 | + tile_y0: 0, | ||
| 9463 | }; | 9605 | }; |
| 9464 | // Every non-`LAST_FRAME` reference this frame header's own `ref_frame_idx` | 9606 | // Every non-`LAST_FRAME` reference this frame header's own `ref_frame_idx` |
| 9465 | // names a live DPB slot for (lane-av1refs: generalised from the old | 9607 | // names a live DPB slot for (lane-av1refs: generalised from the old |
| @@ -9479,6 +9621,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 9479 | height: g.height, | 9621 | height: g.height, |
| 9480 | true_width: g.width, | 9622 | true_width: g.width, |
| 9481 | true_height: g.height, | 9623 | true_height: g.height, |
| 9624 | + tile_x0: 0, | ||
| 9625 | + tile_y0: 0, | ||
| 9482 | }, | 9626 | }, |
| 9483 | PlaneBuf { | 9627 | PlaneBuf { |
| 9484 | data: g.u.clone(), | 9628 | data: g.u.clone(), |
| @@ -9486,6 +9630,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 9486 | height: g.height / 2, | 9630 | height: g.height / 2, |
| 9487 | true_width: g.width / 2, | 9631 | true_width: g.width / 2, |
| 9488 | true_height: g.height / 2, | 9632 | true_height: g.height / 2, |
| 9633 | + tile_x0: 0, | ||
| 9634 | + tile_y0: 0, | ||
| 9489 | }, | 9635 | }, |
| 9490 | PlaneBuf { | 9636 | PlaneBuf { |
| 9491 | data: g.v.clone(), | 9637 | data: g.v.clone(), |
| @@ -9493,6 +9639,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 9493 | height: g.height / 2, | 9639 | height: g.height / 2, |
| 9494 | true_width: g.width / 2, | 9640 | true_width: g.width / 2, |
| 9495 | true_height: g.height / 2, | 9641 | true_height: g.height / 2, |
| 9642 | + tile_x0: 0, | ||
| 9643 | + tile_y0: 0, | ||
| 9496 | }, | 9644 | }, |
| 9497 | ) | 9645 | ) |
| 9498 | }) | 9646 | }) |
| @@ -9506,6 +9654,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 9506 | height, | 9654 | height, |
| 9507 | true_width, | 9655 | true_width, |
| 9508 | true_height, | 9656 | true_height, |
| 9657 | + tile_x0: 0, | ||
| 9658 | + tile_y0: 0, | ||
| 9509 | }; | 9659 | }; |
| 9510 | let mut u = PlaneBuf { | 9660 | let mut u = PlaneBuf { |
| 9511 | data: vec![0u8; width * height / 4], | 9661 | data: vec![0u8; width * height / 4], |
| @@ -9513,6 +9663,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 9513 | height: height / 2, | 9663 | height: height / 2, |
| 9514 | true_width: true_width / 2, | 9664 | true_width: true_width / 2, |
| 9515 | true_height: true_height / 2, | 9665 | true_height: true_height / 2, |
| 9666 | + tile_x0: 0, | ||
| 9667 | + tile_y0: 0, | ||
| 9516 | }; | 9668 | }; |
| 9517 | let mut v = PlaneBuf { | 9669 | let mut v = PlaneBuf { |
| 9518 | data: vec![0u8; width * height / 4], | 9670 | data: vec![0u8; width * height / 4], |
| @@ -9520,6 +9672,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 9520 | height: height / 2, | 9672 | height: height / 2, |
| 9521 | true_width: true_width / 2, | 9673 | true_width: true_width / 2, |
| 9522 | true_height: true_height / 2, | 9674 | true_height: true_height / 2, |
| 9675 | + tile_x0: 0, | ||
| 9676 | + tile_y0: 0, | ||
| 9523 | }; | 9677 | }; |
| 9524 | 9678 | ||
| 9525 | let scan32 = default_scan(TX32); | 9679 | let scan32 = default_scan(TX32); |
| @@ -11462,6 +11616,8 @@ mod tests { | |||
| 11462 | height: height / scale, | 11616 | height: height / scale, |
| 11463 | true_width: width / scale, | 11617 | true_width: width / scale, |
| 11464 | true_height: height / scale, | 11618 | true_height: height / scale, |
| 11619 | + tile_x0: 0, | ||
| 11620 | + tile_y0: 0, | ||
| 11465 | }; | 11621 | }; |
| 11466 | let ref_y = PlaneBuf { | 11622 | let ref_y = PlaneBuf { |
| 11467 | data: ref_pattern.clone(), | 11623 | data: ref_pattern.clone(), |
| @@ -11469,6 +11625,8 @@ mod tests { | |||
| 11469 | height, | 11625 | height, |
| 11470 | true_width: width, | 11626 | true_width: width, |
| 11471 | true_height: height, | 11627 | true_height: height, |
| 11628 | + tile_x0: 0, | ||
| 11629 | + tile_y0: 0, | ||
| 11472 | }; | 11630 | }; |
| 11473 | let ref_u = ref_plane(2); | 11631 | let ref_u = ref_plane(2); |
| 11474 | let ref_v = ref_plane(2); | 11632 | let ref_v = ref_plane(2); |
| @@ -11479,6 +11637,8 @@ mod tests { | |||
| 11479 | height, | 11637 | height, |
| 11480 | true_width: width, | 11638 | true_width: width, |
| 11481 | true_height: height, | 11639 | true_height: height, |
| 11640 | + tile_x0: 0, | ||
| 11641 | + tile_y0: 0, | ||
| 11482 | }; | 11642 | }; |
| 11483 | let mut u = PlaneBuf { | 11643 | let mut u = PlaneBuf { |
| 11484 | data: vec![0u8; (width / 2) * (height / 2)], | 11644 | data: vec![0u8; (width / 2) * (height / 2)], |
| @@ -11486,6 +11646,8 @@ mod tests { | |||
| 11486 | height: height / 2, | 11646 | height: height / 2, |
| 11487 | true_width: width / 2, | 11647 | true_width: width / 2, |
| 11488 | true_height: height / 2, | 11648 | true_height: height / 2, |
| 11649 | + tile_x0: 0, | ||
| 11650 | + tile_y0: 0, | ||
| 11489 | }; | 11651 | }; |
| 11490 | let mut v = PlaneBuf { | 11652 | let mut v = PlaneBuf { |
| 11491 | data: vec![0u8; (width / 2) * (height / 2)], | 11653 | data: vec![0u8; (width / 2) * (height / 2)], |
| @@ -11493,6 +11655,8 @@ mod tests { | |||
| 11493 | height: height / 2, | 11655 | height: height / 2, |
| 11494 | true_width: width / 2, | 11656 | true_width: width / 2, |
| 11495 | true_height: height / 2, | 11657 | true_height: height / 2, |
| 11658 | + tile_x0: 0, | ||
| 11659 | + tile_y0: 0, | ||
| 11496 | }; | 11660 | }; |
| 11497 | 11661 | ||
| 11498 | let mut cdfs = Cdfs::new(q_ctx_of(100)); | 11662 | let mut cdfs = Cdfs::new(q_ctx_of(100)); |
crates/ec-av1/src/refusal_inventory.rsmodified+4 -1
| @@ -48,7 +48,10 @@ const REFUSALS: &[&str] = &[ | |||
| 48 | "a frame naming primary_ref_frame at a reference slot with no saved CDF state", | 48 | "a frame naming primary_ref_frame at a reference slot with no saved CDF state", |
| 49 | "a frame with delta_q_present or delta_lf_present set (this decoder never reads the per-superblock delta symbols)", | 49 | "a frame with delta_q_present or delta_lf_present set (this decoder never reads the per-superblock delta symbols)", |
| 50 | "a frame with loop restoration enabled (this decoder never reads the per-unit lr symbols)", | 50 | "a frame with loop restoration enabled (this decoder never reads the per-unit lr symbols)", |
| 51 | - "a frame with more than one tile (this decoder only ever decodes tile 0)", | 51 | + "a frame with more than one tile row (only tile columns are proven pixel-exact so far)", |
| 52 | + "a frame with more than two tile columns (a non-last column's right-edge reach bound past column 0 is unimplemented)", | ||
| 53 | + "a multi-tile frame with loop filtering enabled (deblocking crosses tile boundaries by spec default; PlaneBuf's tile origin does not clip a non-last column's right-edge reach)", | ||
| 54 | + "an inter frame with more than one tile (the inter tile-decode path has no per-tile loop, only key frames do)", | ||
| 52 | "a frame with no mode-info grid", | 55 | "a frame with no mode-info grid", |
| 53 | "a frame with segmentation enabled (this decoder never reads a per-block segment_id symbol)", | 56 | "a frame with segmentation enabled (this decoder never reads a per-block segment_id symbol)", |
| 54 | "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding", | 57 | "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding", |
crates/ec-av1/src/stream.rsmodified+428 -6
| @@ -278,13 +278,58 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 278 | // `skip_mode_present` refusal is gone. | 278 | // `skip_mode_present` refusal is gone. |
| 279 | // `context_update_tile_id` (spec `decode_tile`/`exit_symbol`) names | 279 | // `context_update_tile_id` (spec `decode_tile`/`exit_symbol`) names |
| 280 | // which tile's end-of-tile adapted CDFs become the frame's own; this | 280 | // which tile's end-of-tile adapted CDFs become the frame's own; this |
| 281 | - // decoder only ever decodes tile 0 (`tiles.first()` above), so a | 281 | + // decoder still only ever *keeps* tile 0's adapted table (see the |
| 282 | - // multi-tile frame is refused rather than silently forwarding the | 282 | + // `context_update_tile_id != 0` refusal further down), so any frame |
| 283 | - // wrong tile's table (or leaving the rest of the picture undecoded). | 283 | + // naming a different tile there is refused rather than silently |
| 284 | - if header.tile_info.cols > 1 || header.tile_info.rows > 1 { | 284 | + // forwarding the wrong tile's table. |
| 285 | + // | ||
| 286 | + // lane-tiles r4: the multi-tile refusal itself is now scoped, not | ||
| 287 | + // blanket. `decode_key_frame_tile_with_cdfs` genuinely loops every | ||
| 288 | + // tile (r2/r3), proven pixel-exact by | ||
| 289 | + // `a_real_aomenc_stream_with_two_tile_columns_decodes_pixel_exact` | ||
| 290 | + // (2 tile columns, `--loopfilter-control=0`) -- but that gate's own | ||
| 291 | + // doc comment names two gaps it deliberately sidesteps, so this | ||
| 292 | + // refusal keeps refusing exactly those: | ||
| 293 | + // - `decode_inter_frame_tile_with_cdfs` takes one `&[u8]` tile | ||
| 294 | + // payload, not a `tiles: &[&[u8]]` list -- it has no per-tile | ||
| 295 | + // loop at all, so an inter frame with >1 tile is still refused | ||
| 296 | + // unconditionally. | ||
| 297 | + // - Deblocking crosses tile boundaries by spec default (AV1 has | ||
| 298 | + // no `loop_filter_across_tiles_enabled`-style flag at all -- | ||
| 299 | + // confirmed absent from `ec-av1-syntax`'s `loop_filter_params` | ||
| 300 | + // read, spec 5.9.11 has no such field either), but `PlaneBuf`'s | ||
| 301 | + // `tile_x0`/`tile_y0` origin only ever clips a tile's own | ||
| 302 | + // left/top reach, not a non-last column's right-edge reach -- | ||
| 303 | + // so a key frame with `loop_filter.level` non-zero (deblocking | ||
| 304 | + // actually on) still refuses. | ||
| 305 | + // - The proven gate is 2 tile *columns*, 1 tile *row*; a | ||
| 306 | + // non-last column's right-edge reach bound past column 0 is | ||
| 307 | + // unimplemented for 3+ columns (r3's own known gap), so `cols` | ||
| 308 | + // is capped at 2. Tile rows are untested this round, so `rows` | ||
| 309 | + // stays capped at 1. | ||
| 310 | + let loop_filter_on = header.loop_filter.level.iter().any(|&l| l != 0); | ||
| 311 | + if header.frame_type != FrameType::Key && header.tile_info.cols > 1 { | ||
| 312 | + return Err(Error::unsupported( | ||
| 313 | + "AV1 decode_stream", | ||
| 314 | + "an inter frame with more than one tile (the inter tile-decode path has no per-tile loop, only key frames do)", | ||
| 315 | + )); | ||
| 316 | + } | ||
| 317 | + if header.tile_info.rows > 1 { | ||
| 318 | + return Err(Error::unsupported( | ||
| 319 | + "AV1 decode_stream", | ||
| 320 | + "a frame with more than one tile row (only tile columns are proven pixel-exact so far)", | ||
| 321 | + )); | ||
| 322 | + } | ||
| 323 | + if header.tile_info.cols > 2 { | ||
| 324 | + return Err(Error::unsupported( | ||
| 325 | + "AV1 decode_stream", | ||
| 326 | + "a frame with more than two tile columns (a non-last column's right-edge reach bound past column 0 is unimplemented)", | ||
| 327 | + )); | ||
| 328 | + } | ||
| 329 | + if header.tile_info.cols > 1 && loop_filter_on { | ||
| 285 | return Err(Error::unsupported( | 330 | return Err(Error::unsupported( |
| 286 | "AV1 decode_stream", | 331 | "AV1 decode_stream", |
| 287 | - "a frame with more than one tile (this decoder only ever decodes tile 0)", | 332 | + "a multi-tile frame with loop filtering enabled (deblocking crosses tile boundaries by spec default; PlaneBuf's tile origin does not clip a non-last column's right-edge reach)", |
| 288 | )); | 333 | )); |
| 289 | } | 334 | } |
| 290 | // `Tile::offset` is relative to the buffer `parse_obu` was handed | 335 | // `Tile::offset` is relative to the buffer `parse_obu` was handed |
| @@ -292,6 +337,13 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 292 | // to `obu_offset`, not to `data` as a whole. | 337 | // to `obu_offset`, not to `data` as a whole. |
| 293 | let start = obu_offset + tile.offset; | 338 | let start = obu_offset + tile.offset; |
| 294 | let tile_bytes = data.get(start..start + tile.size).ok_or(Error::NeedMore)?; | 339 | let tile_bytes = data.get(start..start + tile.size).ok_or(Error::NeedMore)?; |
| 340 | + let tile_bufs: Vec<&[u8]> = tiles | ||
| 341 | + .iter() | ||
| 342 | + .map(|t| { | ||
| 343 | + data.get(obu_offset + t.offset..obu_offset + t.offset + t.size) | ||
| 344 | + .ok_or(Error::NeedMore) | ||
| 345 | + }) | ||
| 346 | + .collect::<Result<_>>()?; | ||
| 295 | let enable_filter_intra = parser | 347 | let enable_filter_intra = parser |
| 296 | .sequence_header() | 348 | .sequence_header() |
| 297 | .is_some_and(|seq| seq.enable_filter_intra); | 349 | .is_some_and(|seq| seq.enable_filter_intra); |
| @@ -352,7 +404,8 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 352 | 404 | ||
| 353 | let (picture, end_cdfs, motion_field) = if header.frame_type == FrameType::Key { | 405 | let (picture, end_cdfs, motion_field) = if header.frame_type == FrameType::Key { |
| 354 | let (picture, end_cdfs) = decode_key_frame_tile_with_cdfs( | 406 | let (picture, end_cdfs) = decode_key_frame_tile_with_cdfs( |
| 355 | - tile_bytes, | 407 | + &tile_bufs, |
| 408 | + &header.tile_info, | ||
| 356 | header.mi_cols, | 409 | header.mi_cols, |
| 357 | header.mi_rows, | 410 | header.mi_rows, |
| 358 | header.quantization.base_q_idx, | 411 | header.quantization.base_q_idx, |
| @@ -5935,4 +5988,373 @@ mod tests { | |||
| 5935 | } | 5988 | } |
| 5936 | } | 5989 | } |
| 5937 | } | 5990 | } |
| 5991 | + | ||
| 5992 | + /// lane-tiles r3: a real two-tile-column aomenc key frame, decoded | ||
| 5993 | + /// through [`decode_key_frame_tile_with_cdfs`] directly with the whole | ||
| 5994 | + /// `tiles: &[&[u8]]` list -- `decode_stream`'s `cols > 1 || rows > 1` | ||
| 5995 | + /// refusal (this file, ~line 292) still fires for any stream this wide, | ||
| 5996 | + /// so this gate bypasses it on purpose to prove the per-tile loop r2 | ||
| 5997 | + /// landed (fresh `SymbolDecoder`/CDF copy per tile, `Neighbours::start_tile`, | ||
| 5998 | + /// `PlaneBuf::set_tile_origin`) actually decodes both tiles pixel-exact | ||
| 5999 | + /// before that refusal is lifted. 128x64 is exactly two 64x64 | ||
| 6000 | + /// superblocks wide with `--tile-columns=1` (`TileCols=2`), so tile 1 is | ||
| 6001 | + /// also the frame's own right edge -- the known gap (`PlaneBuf`'s | ||
| 6002 | + /// tile_x0/tile_y0 only clip left/top reach, not a non-last column's | ||
| 6003 | + /// right-edge reach) does not apply to this fixture; it would to a | ||
| 6004 | + /// 3+-column one. Tile count itself is a structural aomenc param, not | ||
| 6005 | + /// RD-dependent content, but this decoder's chroma smooth/paeth gap | ||
| 6006 | + /// (`decode.rs` "a smooth or paeth chroma mode (round 2)", unrelated to | ||
| 6007 | + /// tiles, pre-dating this lane) is content-dependent -- no aomenc flag | ||
| 6008 | + /// disables UV-only smooth/paeth search, so a small seed sweep is | ||
| 6009 | + /// needed the same way the sibling `a_real_aomenc_stream_with_*` gates | ||
| 6010 | + /// retry past unrelated named refusals (every refusal in this crate is | ||
| 6011 | + /// prefixed `"AV1 tile"` regardless of category, so unlike the sibling | ||
| 6012 | + /// gates' `warp`/`obmc`/`interintra` banned lists there is no | ||
| 6013 | + /// tile-specific substring to forbid here -- `matched > 0` plus the | ||
| 6014 | + /// hard `tile_hits > 1`/pixel-exact asserts on any actual decode are | ||
| 6015 | + /// the real proof). | ||
| 6016 | + #[test] | ||
| 6017 | + fn a_real_aomenc_stream_with_two_tile_columns_decodes_pixel_exact() { | ||
| 6018 | + const NAME: &str = "a_real_aomenc_stream_with_two_tile_columns_decodes_pixel_exact"; | ||
| 6019 | + if !have_ffmpeg() { | ||
| 6020 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 6021 | + return; | ||
| 6022 | + } | ||
| 6023 | + if !have_aomenc() { | ||
| 6024 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 6025 | + return; | ||
| 6026 | + } | ||
| 6027 | + let (width, height) = (128usize, 64usize); | ||
| 6028 | + let mut matched = 0u32; | ||
| 6029 | + let mut named_refusals = 0u32; | ||
| 6030 | + for attempt in 0..20u32 { | ||
| 6031 | + let seed = 42 + attempt; | ||
| 6032 | + let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); | ||
| 6033 | + let y4m = Command::new("ffmpeg") | ||
| 6034 | + .args([ | ||
| 6035 | + "-v", | ||
| 6036 | + "error", | ||
| 6037 | + "-f", | ||
| 6038 | + "lavfi", | ||
| 6039 | + "-i", | ||
| 6040 | + &source, | ||
| 6041 | + "-pix_fmt", | ||
| 6042 | + "yuv420p", | ||
| 6043 | + "-f", | ||
| 6044 | + "yuv4mpegpipe", | ||
| 6045 | + "-", | ||
| 6046 | + ]) | ||
| 6047 | + .stdin(Stdio::null()) | ||
| 6048 | + .stdout(Stdio::piped()) | ||
| 6049 | + .stderr(Stdio::piped()) | ||
| 6050 | + .output() | ||
| 6051 | + .expect("ffmpeg failed to run"); | ||
| 6052 | + assert!( | ||
| 6053 | + y4m.status.success(), | ||
| 6054 | + "ffmpeg fixture: {}", | ||
| 6055 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 6056 | + ); | ||
| 6057 | + let mut child = Command::new(aomenc_path()) | ||
| 6058 | + .args([ | ||
| 6059 | + "--codec=av1", | ||
| 6060 | + "--passes=1", | ||
| 6061 | + "--end-usage=q", | ||
| 6062 | + "--cq-level=45", | ||
| 6063 | + "--cpu-used=0", | ||
| 6064 | + "--limit=1", | ||
| 6065 | + "--kf-max-dist=1000", | ||
| 6066 | + "--threads=1", | ||
| 6067 | + "--row-mt=0", | ||
| 6068 | + "--tile-columns=1", | ||
| 6069 | + "--tile-rows=0", | ||
| 6070 | + // This decoder hardcodes SB_MI=16 (64px) superblocks | ||
| 6071 | + // everywhere (`decode.rs`'s sb128 dead-end, ledger | ||
| 6072 | + // `av1-superblock-contexts`) -- without this, aomenc's | ||
| 6073 | + // own default 128x128 superblock makes 128x64 exactly | ||
| 6074 | + // ONE superblock wide, so `--tile-columns=1` has nothing | ||
| 6075 | + // to split and `cols` comes back 1. | ||
| 6076 | + "--sb-size=64", | ||
| 6077 | + // Deblocking crosses tile boundaries by default (spec | ||
| 6078 | + // `loop_filter_across_tiles_enabled`); `PlaneBuf`'s | ||
| 6079 | + // tile_x0/tile_y0 origin only ever clips a tile's own | ||
| 6080 | + // left/top reach (r2/r3's documented known gap), so a | ||
| 6081 | + // non-last tile column's right-edge deblock would read | ||
| 6082 | + // into the next tile's still-undecoded/differently- | ||
| 6083 | + // origined samples. Off here since deblocking itself is | ||
| 6084 | + // not what this gate is proving. | ||
| 6085 | + "--loopfilter-control=0", | ||
| 6086 | + "--enable-rect-partitions=0", | ||
| 6087 | + "--enable-ab-partitions=0", | ||
| 6088 | + "--enable-1to4-partitions=0", | ||
| 6089 | + "--enable-filter-intra=0", | ||
| 6090 | + "--enable-smooth-intra=0", | ||
| 6091 | + "--enable-paeth-intra=0", | ||
| 6092 | + "--enable-directional-intra=0", | ||
| 6093 | + "--enable-angle-delta=0", | ||
| 6094 | + "--enable-tx-size-search=0", | ||
| 6095 | + "--enable-cdef=0", | ||
| 6096 | + "--enable-restoration=0", | ||
| 6097 | + "--max-partition-size=32", | ||
| 6098 | + "--min-partition-size=32", | ||
| 6099 | + "--enable-palette=0", | ||
| 6100 | + "--enable-intrabc=0", | ||
| 6101 | + "--enable-cfl-intra=0", | ||
| 6102 | + "--obu", | ||
| 6103 | + "-o", | ||
| 6104 | + "-", | ||
| 6105 | + "-", | ||
| 6106 | + ]) | ||
| 6107 | + .stdin(Stdio::piped()) | ||
| 6108 | + .stdout(Stdio::piped()) | ||
| 6109 | + .stderr(Stdio::piped()) | ||
| 6110 | + .spawn() | ||
| 6111 | + .expect("aomenc failed to start"); | ||
| 6112 | + child | ||
| 6113 | + .stdin | ||
| 6114 | + .take() | ||
| 6115 | + .expect("aomenc stdin") | ||
| 6116 | + .write_all(&y4m.stdout) | ||
| 6117 | + .expect("writing y4m to aomenc"); | ||
| 6118 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 6119 | + assert!( | ||
| 6120 | + out.status.success(), | ||
| 6121 | + "aomenc refused the fixture: {}", | ||
| 6122 | + String::from_utf8_lossy(&out.stderr) | ||
| 6123 | + ); | ||
| 6124 | + let stream = out.stdout; | ||
| 6125 | + | ||
| 6126 | + // Parse the stream ourselves (rather than `decode_stream`, whose | ||
| 6127 | + // multi-tile refusal is exactly what this gate exists to run | ||
| 6128 | + // ahead of) to reach the real `Frame` OBU's `tile_info` and its | ||
| 6129 | + // full `Vec<Tile>` -- `Av1Parser::parse_obu` already locates | ||
| 6130 | + // every tile in a multi-tile tile group (`parse_tile_group`), it | ||
| 6131 | + // is only `decode_stream` that ever narrows this to | ||
| 6132 | + // `tiles.first()`. | ||
| 6133 | + let mut parser = Av1Parser::new(); | ||
| 6134 | + let mut pos = 0usize; | ||
| 6135 | + let mut frame = None; | ||
| 6136 | + while pos < stream.len() { | ||
| 6137 | + let obu_offset = pos; | ||
| 6138 | + let obu = parser.parse_obu(&stream[pos..]).unwrap(); | ||
| 6139 | + pos += obu.total_size; | ||
| 6140 | + if let ObuKind::Frame(header, tiles) = obu.kind { | ||
| 6141 | + frame = Some((header, tiles, obu_offset)); | ||
| 6142 | + break; | ||
| 6143 | + } | ||
| 6144 | + } | ||
| 6145 | + let (header, tiles, obu_offset) = frame.expect("stream has a Frame OBU"); | ||
| 6146 | + assert!( | ||
| 6147 | + header.tile_info.cols > 1, | ||
| 6148 | + "{NAME}: aomenc did not actually split into >1 tile column (cols={}, seed {seed})", | ||
| 6149 | + header.tile_info.cols | ||
| 6150 | + ); | ||
| 6151 | + assert_eq!( | ||
| 6152 | + tiles.len(), | ||
| 6153 | + header.tile_info.cols as usize, | ||
| 6154 | + "{NAME}: expected one tile per column (seed {seed})" | ||
| 6155 | + ); | ||
| 6156 | + // `Tile::offset` is relative to the buffer `parse_obu` was | ||
| 6157 | + // handed (`&stream[pos..]` at the time this OBU was parsed), so | ||
| 6158 | + // it needs `obu_offset` added back -- the same adjustment | ||
| 6159 | + // `decode_stream` makes for its own single-tile slice above. | ||
| 6160 | + let tile_bufs: Vec<&[u8]> = tiles | ||
| 6161 | + .iter() | ||
| 6162 | + .map(|t| &stream[obu_offset + t.offset..obu_offset + t.offset + t.size]) | ||
| 6163 | + .collect(); | ||
| 6164 | + | ||
| 6165 | + let enable_filter_intra = parser | ||
| 6166 | + .sequence_header() | ||
| 6167 | + .is_some_and(|seq| seq.enable_filter_intra); | ||
| 6168 | + let enable_edge_filter = parser | ||
| 6169 | + .sequence_header() | ||
| 6170 | + .is_some_and(|seq| seq.enable_intra_edge_filter); | ||
| 6171 | + | ||
| 6172 | + let before = crate::decode::tile_hits(); | ||
| 6173 | + let picture = match decode_key_frame_tile_with_cdfs( | ||
| 6174 | + &tile_bufs, | ||
| 6175 | + &header.tile_info, | ||
| 6176 | + header.mi_cols, | ||
| 6177 | + header.mi_rows, | ||
| 6178 | + header.quantization.base_q_idx, | ||
| 6179 | + header.frame_width, | ||
| 6180 | + header.frame_height, | ||
| 6181 | + enable_filter_intra, | ||
| 6182 | + enable_edge_filter, | ||
| 6183 | + &header.cdef, | ||
| 6184 | + &header.loop_filter, | ||
| 6185 | + None, | ||
| 6186 | + header.tx_mode == TxMode::Select, | ||
| 6187 | + header.reduced_tx_set, | ||
| 6188 | + header.allow_screen_content_tools, | ||
| 6189 | + header.allow_intrabc, | ||
| 6190 | + ) { | ||
| 6191 | + Err(e) => { | ||
| 6192 | + let msg = e.to_string(); | ||
| 6193 | + assert!( | ||
| 6194 | + msg.contains("unsupported"), | ||
| 6195 | + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" | ||
| 6196 | + ); | ||
| 6197 | + named_refusals += 1; | ||
| 6198 | + eprintln!("seed {seed} refusal: {msg}"); | ||
| 6199 | + continue; | ||
| 6200 | + } | ||
| 6201 | + Ok((picture, _end_cdfs)) => picture, | ||
| 6202 | + }; | ||
| 6203 | + let hits = crate::decode::tile_hits() - before; | ||
| 6204 | + assert!( | ||
| 6205 | + hits > 1, | ||
| 6206 | + "{NAME}: tile_hits delta was {hits}, expected >1 -- both tiles must actually \ | ||
| 6207 | + decode, not just tile 0 (seed {seed})" | ||
| 6208 | + ); | ||
| 6209 | + | ||
| 6210 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | ||
| 6211 | + assert_eq!(picture.y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); | ||
| 6212 | + assert_eq!(picture.u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); | ||
| 6213 | + assert_eq!(picture.v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); | ||
| 6214 | + matched += 1; | ||
| 6215 | + } | ||
| 6216 | + assert!( | ||
| 6217 | + matched > 0, | ||
| 6218 | + "{NAME}: every attempt refused ({named_refusals} refusals); the gate never decoded \ | ||
| 6219 | + a two-tile-column stream" | ||
| 6220 | + ); | ||
| 6221 | + eprintln!( | ||
| 6222 | + "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20" | ||
| 6223 | + ); | ||
| 6224 | + } | ||
| 6225 | + | ||
| 6226 | + /// lane-tiles r4: the same real two-tile-column stream as the gate | ||
| 6227 | + /// above, this time run through `decode_stream` itself -- the entry | ||
| 6228 | + /// point real callers use, not the `decode_key_frame_tile_with_cdfs` | ||
| 6229 | + /// bypass. Proves the `cols > 1` refusal is actually lifted (not just | ||
| 6230 | + /// that the underlying per-tile loop works) for the scoped case this | ||
| 6231 | + /// round proved safe: 2 tile columns, 1 tile row, key frame, loop | ||
| 6232 | + /// filtering off (`--loopfilter-control=0` stays -- deblocking crosses | ||
| 6233 | + /// tile boundaries by spec default and `PlaneBuf` cannot bound a | ||
| 6234 | + /// non-last column's right-edge reach yet, see the refusal's own doc | ||
| 6235 | + /// comment above `decode_stream`). | ||
| 6236 | + #[test] | ||
| 6237 | + fn a_real_aomenc_stream_with_two_tile_columns_decodes_through_decode_stream() { | ||
| 6238 | + const NAME: &str = "a_real_aomenc_stream_with_two_tile_columns_decodes_through_decode_stream"; | ||
| 6239 | + if !have_ffmpeg() { | ||
| 6240 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 6241 | + return; | ||
| 6242 | + } | ||
| 6243 | + if !have_aomenc() { | ||
| 6244 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 6245 | + return; | ||
| 6246 | + } | ||
| 6247 | + let (width, height) = (128usize, 64usize); | ||
| 6248 | + let mut matched = 0u32; | ||
| 6249 | + let mut named_refusals = 0u32; | ||
| 6250 | + for attempt in 0..20u32 { | ||
| 6251 | + let seed = 42 + attempt; | ||
| 6252 | + let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); | ||
| 6253 | + let y4m = Command::new("ffmpeg") | ||
| 6254 | + .args([ | ||
| 6255 | + "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", | ||
| 6256 | + "yuv4mpegpipe", "-", | ||
| 6257 | + ]) | ||
| 6258 | + .stdin(Stdio::null()) | ||
| 6259 | + .stdout(Stdio::piped()) | ||
| 6260 | + .stderr(Stdio::piped()) | ||
| 6261 | + .output() | ||
| 6262 | + .expect("ffmpeg failed to run"); | ||
| 6263 | + assert!( | ||
| 6264 | + y4m.status.success(), | ||
| 6265 | + "ffmpeg fixture: {}", | ||
| 6266 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 6267 | + ); | ||
| 6268 | + let mut child = Command::new(aomenc_path()) | ||
| 6269 | + .args([ | ||
| 6270 | + "--codec=av1", | ||
| 6271 | + "--passes=1", | ||
| 6272 | + "--end-usage=q", | ||
| 6273 | + "--cq-level=45", | ||
| 6274 | + "--cpu-used=0", | ||
| 6275 | + "--limit=1", | ||
| 6276 | + "--kf-max-dist=1000", | ||
| 6277 | + "--threads=1", | ||
| 6278 | + "--row-mt=0", | ||
| 6279 | + "--tile-columns=1", | ||
| 6280 | + "--tile-rows=0", | ||
| 6281 | + "--sb-size=64", | ||
| 6282 | + "--loopfilter-control=0", | ||
| 6283 | + "--enable-rect-partitions=0", | ||
| 6284 | + "--enable-ab-partitions=0", | ||
| 6285 | + "--enable-1to4-partitions=0", | ||
| 6286 | + "--enable-filter-intra=0", | ||
| 6287 | + "--enable-smooth-intra=0", | ||
| 6288 | + "--enable-paeth-intra=0", | ||
| 6289 | + "--enable-directional-intra=0", | ||
| 6290 | + "--enable-angle-delta=0", | ||
| 6291 | + "--enable-tx-size-search=0", | ||
| 6292 | + "--enable-cdef=0", | ||
| 6293 | + "--enable-restoration=0", | ||
| 6294 | + "--max-partition-size=32", | ||
| 6295 | + "--min-partition-size=32", | ||
| 6296 | + "--enable-palette=0", | ||
| 6297 | + "--enable-intrabc=0", | ||
| 6298 | + "--enable-cfl-intra=0", | ||
| 6299 | + "--obu", | ||
| 6300 | + "-o", | ||
| 6301 | + "-", | ||
| 6302 | + "-", | ||
| 6303 | + ]) | ||
| 6304 | + .stdin(Stdio::piped()) | ||
| 6305 | + .stdout(Stdio::piped()) | ||
| 6306 | + .stderr(Stdio::piped()) | ||
| 6307 | + .spawn() | ||
| 6308 | + .expect("aomenc failed to start"); | ||
| 6309 | + child | ||
| 6310 | + .stdin | ||
| 6311 | + .take() | ||
| 6312 | + .expect("aomenc stdin") | ||
| 6313 | + .write_all(&y4m.stdout) | ||
| 6314 | + .expect("writing y4m to aomenc"); | ||
| 6315 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 6316 | + assert!( | ||
| 6317 | + out.status.success(), | ||
| 6318 | + "aomenc refused the fixture: {}", | ||
| 6319 | + String::from_utf8_lossy(&out.stderr) | ||
| 6320 | + ); | ||
| 6321 | + let stream = out.stdout; | ||
| 6322 | + | ||
| 6323 | + let before = crate::decode::tile_hits(); | ||
| 6324 | + let pictures = match decode_stream(&stream) { | ||
| 6325 | + Err(e) => { | ||
| 6326 | + let msg = e.to_string(); | ||
| 6327 | + assert!( | ||
| 6328 | + msg.contains("unsupported"), | ||
| 6329 | + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" | ||
| 6330 | + ); | ||
| 6331 | + named_refusals += 1; | ||
| 6332 | + eprintln!("seed {seed} refusal: {msg}"); | ||
| 6333 | + continue; | ||
| 6334 | + } | ||
| 6335 | + Ok(pictures) => pictures, | ||
| 6336 | + }; | ||
| 6337 | + let hits = crate::decode::tile_hits() - before; | ||
| 6338 | + assert!( | ||
| 6339 | + hits > 1, | ||
| 6340 | + "{NAME}: tile_hits delta was {hits}, expected >1 -- both tiles must actually \ | ||
| 6341 | + decode, not just tile 0 (seed {seed})" | ||
| 6342 | + ); | ||
| 6343 | + assert_eq!(pictures.len(), 1, "{NAME}: expected exactly 1 picture (seed {seed})"); | ||
| 6344 | + | ||
| 6345 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | ||
| 6346 | + assert_eq!(pictures[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); | ||
| 6347 | + assert_eq!(pictures[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); | ||
| 6348 | + assert_eq!(pictures[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); | ||
| 6349 | + matched += 1; | ||
| 6350 | + } | ||
| 6351 | + assert!( | ||
| 6352 | + matched > 0, | ||
| 6353 | + "{NAME}: every attempt refused ({named_refusals} refusals); decode_stream never \ | ||
| 6354 | + decoded a two-tile-column stream" | ||
| 6355 | + ); | ||
| 6356 | + eprintln!( | ||
| 6357 | + "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20" | ||
| 6358 | + ); | ||
| 6359 | + } | ||
| 5938 | } | 6360 | } |
lanes/tiles-r2.charter.mdadded+61 -0
| @@ -0,0 +1,61 @@ | |||
| 1 | +# lane-tiles r2 — actually decode the tiles | ||
| 2 | + | ||
| 3 | +Worktree `/home/user/Documents/Code/Rust/edith_codecs-tiles`, branch | ||
| 4 | +`lane-tiles`, at 23f412f. | ||
| 5 | + | ||
| 6 | +## Read first, then write code | ||
| 7 | +- `lanes/tiles.report.md` — r1's report. Its "next lever" section names exact | ||
| 8 | + line ranges and the staging order. Do NOT redo r1's recon (class | ||
| 9 | + `worker-cap-spent-reading`). | ||
| 10 | +- `lanes/tiles.charter.md` — the original charter: the three hard parts | ||
| 11 | + (entropy reset per tile, tile-clipped neighbour availability, | ||
| 12 | + `context_update_tile_id`), the gate rules, the hard rules. Still binding. | ||
| 13 | + | ||
| 14 | +## What r1 landed (1231cd5, suite green 232/0, currently a no-op) | ||
| 15 | +`Neighbours` gained `tile_row0_mi` / `tile_col0_mi` and `start_tile()`, and every | ||
| 16 | +literal-`0` availability check — `skip_txfm_ctx`, `tx_size_context`, | ||
| 17 | +`tx_size_context_rect`, and the has_above / has_left in `decode_inter_block` and | ||
| 18 | +`decode_inter_block8` — now compares against the tile origin instead of 0. | ||
| 19 | +Nothing calls `start_tile()` yet, so the origin stays 0 and behaviour is | ||
| 20 | +unchanged. | ||
| 21 | + | ||
| 22 | +## Still missing (r1's list, verbatim) | ||
| 23 | +- entropy-per-tile restructuring in `decode_key_frame_tile_with_cdfs` / | ||
| 24 | + `decode_inter_frame_tile_with_cdfs` | ||
| 25 | +- `PlaneBuf` tile-pixel-origin clipping — not started | ||
| 26 | +- `mvstack.rs` neighbour scan still frame-relative | ||
| 27 | +- multi-OBU tile-group collection — not started | ||
| 28 | +- the refusal at `stream.rs:294-296` is unchanged and still fires | ||
| 29 | + | ||
| 30 | +## Order — COMMIT AFTER EVERY GREEN STEP | ||
| 31 | +1. Restructure `decode_key_frame_tile_with_cdfs` to loop tiles: fresh msac over | ||
| 32 | + each tile's byte range, fresh copy of the frame's initial CDFs per tile, and | ||
| 33 | + only `context_update_tile_id`'s end-of-tile CDFs kept. Wire `start_tile()` | ||
| 34 | + and the new `PlaneBuf` tile-pixel-origin fields. Prove it on an intra-only | ||
| 35 | + two-tile column split, pixel-exact. COMMIT. | ||
| 36 | +2. Tile rows, then non-uniform spacing. COMMIT. | ||
| 37 | +3. Inter frames — thread the tile origin into `mvstack.rs`'s neighbour scan. | ||
| 38 | + This is where it will break. COMMIT. | ||
| 39 | +4. Several tile-group OBUs per frame. COMMIT. | ||
| 40 | +5. `context_update_tile_id` proven with a stream where it is not tile 0, the | ||
| 41 | + FOLLOWING frame decoding pixel-exact off those inherited CDFs. COMMIT. | ||
| 42 | + | ||
| 43 | +## Gate (mandatory) | ||
| 44 | +Same rules as r1's charter: `EC_AV1_REQUIRE_AOMENC=1` on every run, `-t <seconds>` | ||
| 45 | +on every ffmpeg generate, fixtures through `gradients_source(seed, w, h, tail)`, | ||
| 46 | +aomenc `--threads=1 --row-mt=0` plus tile-columns/tile-rows log2, a frame large | ||
| 47 | +enough to be splittable, and a HARD-asserted thread-local `Cell<usize>` counter | ||
| 48 | +proving more than one tile was decoded. | ||
| 49 | + | ||
| 50 | +## Hard rules | ||
| 51 | +- `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-tiles`. Foreground builds, | ||
| 52 | + `nice -n 19 cargo ... -j4`; give every `cargo test` a timeout of at least | ||
| 53 | + 600000 ms (the suite runs ~3-4 min; a 120 s default kills it mid-run). | ||
| 54 | +- Sibling worktrees (edith_codecs, -chroma, -realworld, -lr, -superres) have | ||
| 55 | + live agents. Never build in or edit them. | ||
| 56 | +- Baseline 232 passed / 0 failed on this tree; main is at 234 with two new | ||
| 57 | + guard tests you inherit at merge. | ||
| 58 | +- NEVER push, never merge, never touch `main`. Commit on `lane-tiles` only. | ||
| 59 | +- 75-turn cap: commit at every green step. Stage 1 alone committed and green is | ||
| 60 | + a good outcome; a perfect uncommitted tree is not. | ||
| 61 | +- End with `lanes/tiles-r2.report.md`, VERDICT on the first line. | ||
lanes/tiles-r3.charter.mdadded+48 -0
| @@ -0,0 +1,48 @@ | |||
| 1 | +# lane-tiles r3 — verify r2's per-tile loop, then finish it | ||
| 2 | + | ||
| 3 | +Worktree `/home/user/Documents/Code/Rust/edith_codecs-tiles`, branch | ||
| 4 | +`lane-tiles`, at d1c2071. | ||
| 5 | + | ||
| 6 | +## State | ||
| 7 | +- `1231cd5` (r1) — tile-origin groundwork in `Neighbours` (`tile_row0_mi`, | ||
| 8 | + `tile_col0_mi`, `start_tile()`), every literal-`0` availability check keyed on | ||
| 9 | + the tile origin. A no-op until something calls `start_tile`. | ||
| 10 | +- `d1c2071` (r2, cap-rescued by the orchestrator) — `decode.rs` +159, | ||
| 11 | + `stream.rs` +3, staged but never committed by r2 and **never seen to compile | ||
| 12 | + or pass anything**. That is your first job: find out what it is. | ||
| 13 | +- `lanes/tiles-r2.charter.md` and `lanes/tiles.charter.md` still govern the | ||
| 14 | + staging, the three hard parts and the gate rules. `lanes/tiles.report.md` has | ||
| 15 | + r1's exact line ranges. | ||
| 16 | + | ||
| 17 | +## Order | ||
| 18 | +1. `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-tiles`, then | ||
| 19 | + `cargo check -p ec-av1 --lib` and, if it compiles, | ||
| 20 | + `EC_AV1_REQUIRE_AOMENC=1 nice -n 19 cargo test -p ec-av1 --lib -j4` | ||
| 21 | + (timeout >= 600000 ms). Report the count against 232/0 for this tree. Getting | ||
| 22 | + d1c2071 green is the whole job until it is green. COMMIT once green. | ||
| 23 | +2. Stage 1 from the r2 charter: the key-frame tile decode as a per-tile loop — | ||
| 24 | + fresh msac over each tile's byte range, a fresh copy of the frame's initial | ||
| 25 | + CDFs per tile, only `context_update_tile_id`'s end-of-tile CDFs kept, and | ||
| 26 | + `start_tile()` wired along with the `PlaneBuf` tile-pixel-origin fields. | ||
| 27 | + Proven on an intra-only two-tile column split, pixel-exact, with a | ||
| 28 | + hard-asserted thread-local count of tiles decoded `> 1`. COMMIT. | ||
| 29 | +3. Then tile rows and non-uniform spacing; then inter frames (thread the tile | ||
| 30 | + origin into `mvstack.rs`'s neighbour scan — this is where it will break); | ||
| 31 | + then several tile-group OBUs per frame; then `context_update_tile_id` proven | ||
| 32 | + with a stream where it is not tile 0. One commit each. | ||
| 33 | + | ||
| 34 | +## Note for the merge | ||
| 35 | +Main carries two guards you do not have: `gate_coverage.rs` (pins the aomenc | ||
| 36 | +tools no gate exercises) and `refusal_inventory.rs` (pins every decode-path | ||
| 37 | +refusal string, so adding, renaming or removing one — including the multi-tile | ||
| 38 | +refusal you are here to delete — fails until the list is updated). Report the | ||
| 39 | +refusal strings you change, verbatim. | ||
| 40 | + | ||
| 41 | +## Hard rules | ||
| 42 | +Foreground builds `nice -n 19 cargo ... -j4`, own `CARGO_TARGET_DIR` as above, | ||
| 43 | +every `cargo test` a timeout >= 600000 ms. Sibling worktrees (edith_codecs, | ||
| 44 | +-chroma, -realworld, -lr, -superres, -palette) have live agents — never build in | ||
| 45 | +or edit them. Never push, never merge, never touch `main`. 75-turn cap, does not | ||
| 46 | +reset: COMMIT AT EVERY GREEN STEP — both rounds on this lane so far ended with | ||
| 47 | +work uncommitted. Stage 1 committed and green is a good round on its own. End | ||
| 48 | +with `lanes/tiles-r3.report.md`, VERDICT on line 1. | ||
lanes/tiles-r3.report.mdadded+67 -0
| @@ -0,0 +1,67 @@ | |||
| 1 | +VERDICT: PARTIAL -- step 1 (confirm) and step 2 (prove) done and committed; step 3 | ||
| 2 | +(lift the refusal) not attempted, out of turn budget. | ||
| 3 | + | ||
| 4 | +## Step 1: confirmation run | ||
| 5 | +`cargo check -p ec-av1 --tests` clean. `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 | ||
| 6 | +--lib -j4`: 232 passed, 0 failed, 17 ignored, 207.55s -- matches the corrected charter | ||
| 7 | +note exactly. Nothing to commit (tree was already clean at d1c2071). | ||
| 8 | + | ||
| 9 | +## Step 2: prove the per-tile loop on a real two-tile-column stream | ||
| 10 | +Added `a_real_aomenc_stream_with_two_tile_columns_decodes_pixel_exact` to | ||
| 11 | +`crates/ec-av1/src/stream.rs` (committed 1648317). It: | ||
| 12 | +- builds a 128x64 aomenc key frame with `--tile-columns=1 --tile-rows=0 | ||
| 13 | + --sb-size=64 --loopfilter-control=0`, 20-seed sweep (structural tile split | ||
| 14 | + isn't content-dependent, but this decoder's pre-existing chroma | ||
| 15 | + smooth/paeth refusal is -- accepted as a named refusal like every sibling | ||
| 16 | + gate does for unrelated capabilities); | ||
| 17 | +- parses the stream itself (not `decode_stream`, whose `cols > 1 || rows > 1` | ||
| 18 | + refusal is exactly what this gate runs ahead of) to get the real `Vec<Tile>` | ||
| 19 | + `Av1Parser::parse_obu` already produces; | ||
| 20 | +- calls `decode_key_frame_tile_with_cdfs(&[tile0, tile1], &header.tile_info, | ||
| 21 | + ...)` directly; | ||
| 22 | +- hard-asserts `tile_hits()` delta `> 1` and pixel-exactness against ffmpeg. | ||
| 23 | + | ||
| 24 | +Result: 20/20 pixel-exact matches, 0 refusals, tile_hits > 1 every time. | ||
| 25 | +`cargo check -p ec-av1 --tests` clean after. | ||
| 26 | + | ||
| 27 | +Two things needed beyond the charter's one-liner: | ||
| 28 | +- `--sb-size=64`: this decoder hardcodes 64px superblocks everywhere | ||
| 29 | + (SB_MI=16); aomenc's own default is 128px SBs, which makes 128x64 exactly | ||
| 30 | + one superblock -- nothing for `--tile-columns=1` to split, `cols` came back | ||
| 31 | + 1 without this. | ||
| 32 | +- `--loopfilter-control=0`: deblocking crosses tile boundaries by spec | ||
| 33 | + default, and `PlaneBuf`'s `tile_x0`/`tile_y0` only ever clip a tile's own | ||
| 34 | + left/top reach (the exact known gap r2 flagged) -- a non-last column's | ||
| 35 | + right-edge deblock read into the next tile wrong without this. Sidestepped | ||
| 36 | + on purpose; not fixed, deblocking is not what this gate proves. | ||
| 37 | + | ||
| 38 | +Also caught and fixed a real bug in my own first draft while wiring the test: | ||
| 39 | +`Tile::offset` is relative to the buffer `parse_obu` was handed, not absolute | ||
| 40 | +in `stream` -- forgetting to add `obu_offset` back (the way `decode_stream` | ||
| 41 | +already does at its own tile-extraction site) fed the decoder garbage-offset | ||
| 42 | +bytes, which silently decoded as an all-skip flat DC block per tile (128/127 | ||
| 43 | +uniform) instead of erroring -- a quiet false negative, not a crash. Fixed | ||
| 44 | +before committing; the committed test carries a comment on this. | ||
| 45 | + | ||
| 46 | +## Step 3: not attempted | ||
| 47 | +Lifting the `cols > 1 || rows > 1` refusal in `decode_stream` needs more than | ||
| 48 | +deleting the `if`: the call site currently hardcodes `&[tile_bytes]` (single | ||
| 49 | +tile, `tiles.first()`), so it needs building the full `tile_bufs: Vec<&[u8]>` | ||
| 50 | +the same way this gate's test code now does (including the `obu_offset` fix), | ||
| 51 | +threaded through for BOTH `decode_key_frame_tile_with_cdfs` and | ||
| 52 | +`decode_inter_frame_tile_with_cdfs`. More importantly, real streams | ||
| 53 | +`decode_stream` sees do NOT get `--loopfilter-control=0` for free -- lifting | ||
| 54 | +the refusal for general (non-test-controlled) multi-tile streams would need | ||
| 55 | +either the right-edge reach gap actually fixed in `PlaneBuf`, or deblocking | ||
| 56 | +proven to not cross tile boundaries in the streams under test | ||
| 57 | +(`loop_filter_across_tiles_enabled` -- unread, not checked this round). | ||
| 58 | +Doing this without checking would very likely reintroduce the exact luma | ||
| 59 | +mismatch this round diagnosed (uncaught first-draft bug notwithstanding) for | ||
| 60 | +any real multi-tile stream with loop filtering on. Left for the next round; | ||
| 61 | +the intra-only case specifically (per charter step 3) still needs the deblock | ||
| 62 | +question answered first. | ||
| 63 | + | ||
| 64 | +## Refusal strings | ||
| 65 | +None added, renamed or removed this round -- the multi-tile refusal in | ||
| 66 | +`stream.rs` is untouched. (Step 3, when attempted, will need to report this | ||
| 67 | +line verbatim before deleting it, per the charter's merge note.) | ||
lanes/tiles-r4.charter.mdadded+47 -0
| @@ -0,0 +1,47 @@ | |||
| 1 | +# lane-tiles r4 — lift the multi-tile refusal | ||
| 2 | + | ||
| 3 | +At 477f972. Read `lanes/tiles-r3.report.md`. | ||
| 4 | + | ||
| 5 | +## State | ||
| 6 | +The per-tile loop works and is proven: gate | ||
| 7 | +`a_real_aomenc_stream_with_two_tile_columns_decodes_pixel_exact` (stream.rs | ||
| 8 | +~5484) decodes 20/20 pixel-exact with `tile_hits()` hard-asserted `> 1`, by | ||
| 9 | +calling `decode_key_frame_tile_with_cdfs(&[tile0, tile1], ...)` directly and | ||
| 10 | +bypassing the still-live refusal in `decode_stream`. | ||
| 11 | + | ||
| 12 | +Facts r3 paid for: `--sb-size=64` is required (this decoder hardcodes 64px | ||
| 13 | +superblocks; aomenc's default 128px makes a 128x64 frame a single superblock | ||
| 14 | +with nothing to split). `--loopfilter-control=0` is required *for now* because | ||
| 15 | +deblocking crosses tile boundaries by spec default while `PlaneBuf`'s | ||
| 16 | +`tile_x0`/`tile_y0` clip left/top reach only. And a trap that produced a FALSE | ||
| 17 | +PASS: `Tile::offset` is relative to the slice handed to `parse_obu`, not | ||
| 18 | +absolute — forgetting to add `obu_offset` back decoded flat all-skip DC garbage | ||
| 19 | +that compared "equal" instead of erroring. | ||
| 20 | + | ||
| 21 | +## Your job | ||
| 22 | +1. Read `loop_filter_across_tiles_enabled` in `ec-av1-syntax`'s header parse — | ||
| 23 | + grep it first, it may not be parsed at all. Real multi-tile streams reaching | ||
| 24 | + `decode_stream` get no `--loopfilter-control=0` escape hatch, so this | ||
| 25 | + question has to be answered before the refusal comes off. | ||
| 26 | +2. Thread a real `tile_bufs: Vec<&[u8]>` through `decode_stream`'s key-frame AND | ||
| 27 | + inter-frame tile-decode call sites (both currently hardcode | ||
| 28 | + `&[tile_bytes]`), mirroring r3's `obu_offset`-corrected extraction. | ||
| 29 | +3. Lift the `cols > 1 || rows > 1` refusal for the cases you can prove, and | ||
| 30 | + refuse the rest BY NAME with an accurate string. Re-run r3's gate through | ||
| 31 | + `decode_stream` itself, and drop `--loopfilter-control=0` from it once the | ||
| 32 | + crossing question is resolved to see whether it still holds. COMMIT. | ||
| 33 | +4. Then tile rows, non-uniform spacing, inter frames (tile origin into | ||
| 34 | + `mvstack.rs`), several tile-group OBUs, and `context_update_tile_id != 0`. | ||
| 35 | + Also still open: a non-last tile column's right-edge reach bound is | ||
| 36 | + unimplemented (fine for 2 columns, wrong for 3+). | ||
| 37 | + | ||
| 38 | +Merge note: main is at 06d29ee with `gate_coverage.rs` and `refusal_inventory.rs`, | ||
| 39 | +which pin the aomenc tools no gate exercises and every decode-path refusal | ||
| 40 | +string — including the multi-tile refusal you are here to remove. Report every | ||
| 41 | +refusal string you add, rename or remove, verbatim. | ||
| 42 | + | ||
| 43 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-tiles`; foreground | ||
| 44 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms. Sibling | ||
| 45 | +worktrees have live agents — never build in or edit them. Never push, never | ||
| 46 | +merge, never touch `main`. 75-turn cap, does not reset: COMMIT AT EVERY GREEN | ||
| 47 | +STEP. End with `lanes/tiles-r4.report.md`, VERDICT on line 1. | ||
lanes/tiles-r4.report.mdadded+80 -0
| @@ -0,0 +1,80 @@ | |||
| 1 | +VERDICT: PARTIAL -- steps 1-3 done and committed (9962fb1); step 4 (tile rows, | ||
| 2 | +non-uniform spacing, inter frames, several tile-group OBUs, | ||
| 3 | +context_update_tile_id != 0) not attempted, out of scope this round. | ||
| 4 | + | ||
| 5 | +## Step 1: `loop_filter_across_tiles_enabled` | ||
| 6 | +Grepped `crates/ec-av1-syntax/src/frame.rs`'s `read_loop_filter_params` (spec | ||
| 7 | +5.9.11) end to end: the field does not exist, and it isn't a gap in this | ||
| 8 | +crate's parser -- AV1's spec `loop_filter_params()` has no such syntax | ||
| 9 | +element at all (unlike HEVC's `loop_filter_across_tiles_enabled` PPS flag, | ||
| 10 | +which the charter's naming echoes but AV1 has no equivalent of). Deblocking | ||
| 11 | +crosses tile boundaries unconditionally whenever `loop_filter.level` is | ||
| 12 | +non-zero; there is no per-stream bit that turns it off. That answers the | ||
| 13 | +charter's question: the refusal cannot be conditioned on a header field, | ||
| 14 | +only on whether loop filtering is on at all (`level.iter().any(|&l| l != 0)`) | ||
| 15 | +combined with the already-known `PlaneBuf` gap (tile origin clips a tile's | ||
| 16 | +own left/top reach, never a non-last column's right-edge reach). | ||
| 17 | + | ||
| 18 | +## Step 2: thread real `tile_bufs` through `decode_stream` | ||
| 19 | +`crates/ec-av1/src/stream.rs`'s key-frame call site now builds | ||
| 20 | +`tile_bufs: Vec<&[u8]>` from every element of the OBU's own `tiles: Vec<Tile>` | ||
| 21 | +(the same `obu_offset + t.offset` correction r3's gate proved necessary) and | ||
| 22 | +passes `&tile_bufs` to `decode_key_frame_tile_with_cdfs` instead of the old | ||
| 23 | +`&[tile_bytes]` (tile 0 only). The inter-frame call site still passes the | ||
| 24 | +single `tile_bytes` it always did -- `decode_inter_frame_tile_with_cdfs` | ||
| 25 | +takes one `&[u8]`, not a tile list, and has no per-tile loop at all; widening | ||
| 26 | +that signature is real work left for step 4 ("inter frames (tile origin into | ||
| 27 | +mvstack.rs)"), not attempted this round. | ||
| 28 | + | ||
| 29 | +## Step 3: lift the refusal, scoped; re-run r3's gate through `decode_stream` | ||
| 30 | +The blanket `cols > 1 || rows > 1` refusal is now four scoped refusals, only | ||
| 31 | +firing for what is genuinely still unproven: | ||
| 32 | +- inter frame with `cols > 1` (no per-tile loop on that path at all) | ||
| 33 | +- `rows > 1` (tile rows never tested) | ||
| 34 | +- `cols > 2` (non-last column's right-edge reach bound past column 0 is | ||
| 35 | + unimplemented -- r3's own documented gap, matters starting at 3 columns) | ||
| 36 | +- multi-tile frame with `loop_filter.level` non-zero anywhere (deblocking | ||
| 37 | + crossing gap from step 1) | ||
| 38 | + | ||
| 39 | +A key frame with exactly 2 tile columns, 1 tile row, and loop filtering off | ||
| 40 | +now decodes through `decode_stream` itself. New test | ||
| 41 | +`a_real_aomenc_stream_with_two_tile_columns_decodes_through_decode_stream` | ||
| 42 | +(`stream.rs`, next to r3's gate) runs the identical aomenc recipe through | ||
| 43 | +`decode_stream(&stream)` instead of the hand-parsed bypass: 20/20 pixel-exact, | ||
| 44 | +`tile_hits()` delta `> 1` every attempt, `pictures.len() == 1`. | ||
| 45 | + | ||
| 46 | +Did not drop `--loopfilter-control=0` from either gate -- step 1 established | ||
| 47 | +that would hit the still-unfixed `PlaneBuf` cross-tile-column reach gap | ||
| 48 | +(the new refusal explicitly names this and blocks it before it can silently | ||
| 49 | +miscode), not something worth testing-then-reverting this round. | ||
| 50 | + | ||
| 51 | +## Full suite | ||
| 52 | +`cargo check -p ec-av1 --tests`: clean (only pre-existing doc-lint warnings). | ||
| 53 | +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j4`: 234 passed, 0 | ||
| 54 | +failed, 17 ignored, 146.97s -- both tile gates included, nothing else moved. | ||
| 55 | + | ||
| 56 | +## Refusal strings | ||
| 57 | + | ||
| 58 | +Removed (verbatim, was the single blanket refusal): | ||
| 59 | +> a frame with more than one tile (this decoder only ever decodes tile 0) | ||
| 60 | + | ||
| 61 | +Added, four in its place (all in `stream.rs`, all `Error::unsupported("AV1 | ||
| 62 | +decode_stream", ...)`): | ||
| 63 | +> an inter frame with more than one tile (the inter tile-decode path has no per-tile loop, only key frames do) | ||
| 64 | + | ||
| 65 | +> a frame with more than one tile row (only tile columns are proven pixel-exact so far) | ||
| 66 | + | ||
| 67 | +> a frame with more than two tile columns (a non-last column's right-edge reach bound past column 0 is unimplemented) | ||
| 68 | + | ||
| 69 | +> a multi-tile frame with loop filtering enabled (deblocking crosses tile boundaries by spec default; PlaneBuf's tile origin does not clip a non-last column's right-edge reach) | ||
| 70 | + | ||
| 71 | +## Still open (per charter step 4, unattempted) | ||
| 72 | +Tile rows, non-uniform tile spacing, inter-frame multi-tile decode (needs | ||
| 73 | +`decode_inter_frame_tile_with_cdfs` to grow the same per-tile loop | ||
| 74 | +`decode_key_frame_tile_with_cdfs` already has, plus tile origin threaded into | ||
| 75 | +`mvstack.rs` for inter prediction/MV candidates that reach across a tile | ||
| 76 | +boundary), several tile-group OBUs per frame, `context_update_tile_id != 0` | ||
| 77 | +(this decoder still only ever keeps tile 0's adapted CDF table as the frame's | ||
| 78 | +output regardless of what the header names), and the 3+-column right-edge | ||
| 79 | +reach bound in `PlaneBuf` itself (currently hard-refused via the `cols > 2` | ||
| 80 | +check above rather than silently miscoding). | ||
lanes/tiles.charter.mdadded+96 -0
| @@ -0,0 +1,96 @@ | |||
| 1 | +# lane-tiles — multi-tile decode | ||
| 2 | + | ||
| 3 | +Worktree `/home/user/Documents/Code/Rust/edith_codecs-tiles`, branch | ||
| 4 | +`lane-tiles`, off main (48a6e29 or later). | ||
| 5 | + | ||
| 6 | +## Goal | ||
| 7 | +Remove the refusal at `crates/ec-av1/src/stream.rs:293-298` | ||
| 8 | +("a frame with more than one tile (this decoder only ever decodes tile 0)") | ||
| 9 | +by decoding every tile of every tile group, in order, into one picture. | ||
| 10 | + | ||
| 11 | +## What is already there | ||
| 12 | +- `crates/ec-av1-syntax/src/frame.rs:115` `TileInfo` already carries everything | ||
| 13 | + the walk needs: `cols`, `rows`, `cols_log2`, `rows_log2`, `mi_col_starts` | ||
| 14 | + (`TileCols + 1` entries, 4x4 units), `mi_row_starts`, `context_update_tile_id`, | ||
| 15 | + `tile_size_bytes`. The uniform/non-uniform spacing derivation is at | ||
| 16 | + `frame.rs:1292` onward and is already implemented — READ it, do not re-derive. | ||
| 17 | +- The tile-group OBU parse already produces per-tile `offset`/`size`; today | ||
| 18 | + `stream.rs` takes `tiles.first()` and drops the rest. `Tile::offset` is | ||
| 19 | + relative to the OBU buffer, not to `data` — see the comment at stream.rs:298. | ||
| 20 | +- The superblock walk lives in `crates/ec-av1/src/decode.rs` (two sites, around | ||
| 21 | + lines 4547 and 9275: `for sb_r in 0..sb_rows { for sb_c ... }`). Today those | ||
| 22 | + bounds are the whole frame; per tile they become the tile's own sb range | ||
| 23 | + derived from `mi_row_starts[t]..mi_row_starts[t+1]`. | ||
| 24 | + | ||
| 25 | +## The three things that make tiles more than a loop | ||
| 26 | +1. **Entropy reset per tile.** Each tile starts a FRESH msac decoder over its | ||
| 27 | + own byte range AND a fresh copy of the frame's initial CDFs (spec 5.11.2 | ||
| 28 | + `decode_tile`: `init_symbol` + `clear_above_context`). Only the tile named by | ||
| 29 | + `context_update_tile_id` has its END-of-tile adapted CDFs saved as the | ||
| 30 | + frame's output tables (spec `exit_symbol`) — every other tile's adaptation is | ||
| 31 | + discarded. This is exactly what the current refusal comment warns about. | ||
| 32 | +2. **Context reset at tile boundaries.** Above-context arrays are cleared at the | ||
| 33 | + start of each tile ROW of superblocks within the tile; left-context at each | ||
| 34 | + superblock row. Neighbour availability MUST be clipped to the tile: a block | ||
| 35 | + at the tile's left edge has NO left neighbour even though a decoded block | ||
| 36 | + sits there in the picture. Same for above. Grep libaom | ||
| 37 | + `av1/decoder/decodeframe.c` `av1_tile_init`/`av1_tile_set_col`/ | ||
| 38 | + `av1_tile_set_row` and `av1/common/tile_common.c`; the availability | ||
| 39 | + predicates are `xd->left_available` / `xd->up_available`, set in | ||
| 40 | + `set_mi_row_col` (av1/common/blockd.h). Deblocking and CDEF, by contrast, | ||
| 41 | + run ACROSS tile boundaries unless `loop_filter_across_tiles` says otherwise — | ||
| 42 | + check the actual v3.13.3 source, AV1 has no such flag in the final spec but | ||
| 43 | + verify rather than assume. | ||
| 44 | + Also check the mv-stack / ref-mv scan (`crates/ec-av1/src/mvstack.rs`) and | ||
| 45 | + the CDEF/deblock neighbour reads for the same tile clipping. | ||
| 46 | +3. **Tile ordering across tile groups.** A frame may carry several tile-group | ||
| 47 | + OBUs; tiles are numbered `tg_start..tg_end` globally. | ||
| 48 | + | ||
| 49 | +## Method | ||
| 50 | +CLASS `compare-range-not-tell`: compare the msac RANGE against the oracle after | ||
| 51 | +each element, never `tell()`. The instrumented oracle is at `~/.cache/aom-oracle` | ||
| 52 | +with env-gated rungs (`EC_TRACE=1` partitions, `EC_TRACE_COEFF=1`, | ||
| 53 | +`EC_TRACE_MODE=1`); `scripts/instrument-aom-oracle.sh` + `scripts/build-aom-oracle.sh` | ||
| 54 | +add and rebuild rungs. If you need a per-tile rung (tile index at each | ||
| 55 | +`decode_tile` entry), add one in the existing shape: env-gated, silent when | ||
| 56 | +unset, idempotent, wrapper-around-impl. | ||
| 57 | +CLASS `equal-range-means-unread`: reference range unchanged where ours moves = | ||
| 58 | +we read a symbol it never wrote; theirs moves and ours does not = we skipped one. | ||
| 59 | + | ||
| 60 | +## Staging — COMMIT AFTER EVERY GREEN MILESTONE (75-turn cap; builders have lost whole implementations here) | ||
| 61 | +1. Two tiles, one column split, all-intra key frame. COMMIT. | ||
| 62 | +2. Tile rows as well as columns; non-uniform spacing. COMMIT. | ||
| 63 | +3. Inter frames (mv-stack + neighbour clipping is where this will break). COMMIT. | ||
| 64 | +4. Several tile-group OBUs per frame. COMMIT. | ||
| 65 | +5. `context_update_tile_id` proven: a stream where it is NOT tile 0, decoding | ||
| 66 | + pixel-exact across the following frame (which inherits those CDFs). COMMIT. | ||
| 67 | + | ||
| 68 | +## Gate (mandatory, in `crates/ec-av1/src/stream.rs` beside the existing gates) | ||
| 69 | +- Copy the existing gate shape. Tests must be run with `EC_AV1_REQUIRE_AOMENC=1` | ||
| 70 | + so a missing oracle FAILS instead of SKIPping. | ||
| 71 | +- Bound every ffmpeg `generate` with `-t <seconds>` (an unbounded source once | ||
| 72 | + hung a gate for an hour). | ||
| 73 | +- Build fixtures through the existing `gradients_source(seed, w, h, tail)` | ||
| 74 | + helper — ffmpeg's `gradients` ignores its own seed, so a hand-written | ||
| 75 | + `gradients=size=` string makes the gate non-reproducible. | ||
| 76 | +- aomenc: `--threads=1 --row-mt=0` plus `--tile-columns=1 --tile-rows=1` | ||
| 77 | + (log2 values in aomenc) on a frame large enough that the tiles are legal — | ||
| 78 | + a 64x64 frame cannot be split, so size the fixture accordingly. | ||
| 79 | +- Hard-assert a firing count: a thread-local `Cell<usize>` counter in decode.rs | ||
| 80 | + matching the existing `*_HITS` (thread-local, NOT atomics), incremented per | ||
| 81 | + tile decoded, asserted `> 1`. CLASS `gate-blind-to-feature`: a gate that | ||
| 82 | + cannot prove its feature fired is vacuous. | ||
| 83 | +- Refusals inside the gate are FORBIDDEN once the stage removing them lands. | ||
| 84 | + | ||
| 85 | +## Hard rules | ||
| 86 | +- `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-tiles`. Foreground builds | ||
| 87 | + only, `nice -n 19 cargo ... -j4`. Never build in or edit another worktree: | ||
| 88 | + edith_codecs, -chroma, -realworld, -lr, -superres all have agents in them NOW. | ||
| 89 | +- Suite: `nice -n 19 cargo test -p ec-av1 --lib`, baseline 232 passed / 0 failed | ||
| 90 | + (~67 s). It stays green. | ||
| 91 | +- NEVER push, never merge, never touch `main`. Commit on `lane-tiles` only. | ||
| 92 | +- Refuse-by-name rather than desync; never write a refusal string claiming the | ||
| 93 | + encoder cannot emit a case unless you proved it (class | ||
| 94 | + `refusal-claim-disproved-by-its-own-gate`). | ||
| 95 | +- End with `lanes/tiles.report.md`: what landed, gate name + firing count, | ||
| 96 | + remaining refusal strings verbatim, next lever. | ||
lanes/tiles.report.mdadded+116 -0
| @@ -0,0 +1,116 @@ | |||
| 1 | +# lane-tiles report | ||
| 2 | + | ||
| 3 | +## What landed | ||
| 4 | +Groundwork only, commit `1231cd5` on branch `lane-tiles`: | ||
| 5 | +`crates/ec-av1/src/decode.rs` | ||
| 6 | +- `Neighbours` gained `tile_row0_mi`/`tile_col0_mi` (spec `MiRowStart`/ | ||
| 7 | + `MiColStart`), default `0`, and `start_tile(row0_mi, col0_mi, col1_mi)` | ||
| 8 | + (spec `decode_tile`'s `clear_above_context` over the tile's own column | ||
| 9 | + span; left-context reset per SB row was already unconditional and needed | ||
| 10 | + no change). | ||
| 11 | +- Every availability check that compared a raw mi position against literal | ||
| 12 | + `0` now compares against the tile origin instead: `skip_txfm_ctx`, | ||
| 13 | + `tx_size_context`, `tx_size_context_rect`, and `decode_inter_block`/ | ||
| 14 | + `decode_inter_block8`'s `has_above`/`has_left`. | ||
| 15 | +- Behaviourally a no-op today: nothing calls `start_tile`, so the origin | ||
| 16 | + stays `(0, 0)` everywhere and every existing test is bit-identical. | ||
| 17 | + | ||
| 18 | +The refusal at `crates/ec-av1/src/stream.rs:292-297` ("a frame with more | ||
| 19 | +than one tile") is **unchanged and still fires** — it was not removed. | ||
| 20 | + | ||
| 21 | +## Why it stops here (turn budget) | ||
| 22 | +Recon (charter + call-site tracing across `decode.rs`, `mvstack.rs`, | ||
| 23 | +`ec-av1-syntax/frame.rs`'s `TileInfo`/`parse_tile_group`) took the first | ||
| 24 | +~35 tool calls to establish the real shape of the three hard parts. What | ||
| 25 | +full removal of the refusal needs, none of which is done: | ||
| 26 | +1. **Entropy per tile.** `decode_key_frame_tile_with_cdfs` / | ||
| 27 | + `decode_inter_frame_tile_with_cdfs` each take one `data: &[u8]` and run | ||
| 28 | + one `SymbolDecoder`/`cdfs` over the whole `for sb_r in 0..sb_rows { for | ||
| 29 | + sb_c in 0..sb_cols }` walk. This needs restructuring into a `for tile in | ||
| 30 | + &tiles` outer loop: fresh `SymbolDecoder` per tile's own byte range | ||
| 31 | + (`Tile::offset` is relative to the OBU, already handled correctly in | ||
| 32 | + stream.rs for tile 0 today), fresh `cdfs = initial_cdfs.clone()` per | ||
| 33 | + tile, sb range narrowed to `mi_row_starts[t]/SB_MI..mi_row_starts[t+1]/ | ||
| 34 | + SB_MI` (same for cols), and only `context_update_tile_id`'s own | ||
| 35 | + end-of-tile `cdfs` returned as the frame's adapted table. `TileInfo` | ||
| 36 | + already carries everything this needs (`frame.rs:115`); the derivation | ||
| 37 | + at `frame.rs:1292` confirms `mi_col_starts`/`mi_row_starts` are always | ||
| 38 | + fully populated by the real parser, including the `cols==rows==1` case. | ||
| 39 | +2. **Context clipping — partially wired, NOT complete.** This commit's | ||
| 40 | + `Neighbours` change covers the context-symbol reads it touched. Two | ||
| 41 | + things it does **not** cover: | ||
| 42 | + - `PlaneBuf::edges`/`edges_rect` (`decode.rs` ~2653-2696) still gate | ||
| 43 | + intra-prediction pixel reach on `x > 0`/`y > 0` — a block at a tile's | ||
| 44 | + own left/top edge would read real reconstructed pixels from the | ||
| 45 | + PREVIOUS tile (decoded earlier, sitting right there in the shared | ||
| 46 | + buffer) instead of treating them as unavailable, which is a real | ||
| 47 | + pixel-value bug per spec (AV1 tiles are independently decodable; | ||
| 48 | + intra prediction does not cross tile boundaries). Needs a | ||
| 49 | + `tile_x0`/`tile_y0` pair on `PlaneBuf` (luma-pixel and chroma-pixel | ||
| 50 | + scaled, i.e. `mi_col0*4`/`mi_col0*2`), set before each tile, checked | ||
| 51 | + in `edges`/`edges_rect` in place of `0`. | ||
| 52 | + - `mvstack.rs`'s `find_mv_stack_with_sign_bias` (the actual MV | ||
| 53 | + neighbour scan for every inter block) still hardcodes | ||
| 54 | + `mi_row > 0`/`mi_col > 0` for `max_row_offset`/`max_col_offset` and | ||
| 55 | + `found_above`/`found_left` (its own doc comment at line ~690 already | ||
| 56 | + flags this: *"clamped to the tile's near edge (single-tile-per-frame | ||
| 57 | + here, so that's just the frame edge at 0)"*). `find_samples`/ | ||
| 58 | + `num_proj_ref` (`decode.rs` ~5488/5617, warp-sample gathering for | ||
| 59 | + `WARPED_CAUSAL`) have the same gap. Neither was touched this round. | ||
| 60 | + - Deblock/CDEF were confirmed (not just assumed) to run across the | ||
| 61 | + whole picture after all tiles decode (`apply_deblock`/`apply_cdef` | ||
| 62 | + calls sit after the SB loop, once, over the full `y`/`u`/`v`) — | ||
| 63 | + these need **no** tile clipping, matching the charter's note. | ||
| 64 | +3. **Tile-group ordering.** Not started. `ObuKind::Frame(header, tiles)`'s | ||
| 65 | + `tiles: Vec<Tile>` already spans every tile in `tg_start..tg_end` for a | ||
| 66 | + *single* OBU (`parse_tile_group`, `ec-av1-syntax/src/frame.rs:1992`), | ||
| 67 | + which covers the common `--tile-columns`/`--tile-rows` aomenc case (one | ||
| 68 | + `OBU_FRAME` carries every tile). The separate multi-OBU case | ||
| 69 | + (`ObuKind::FrameHeader` followed by one or more standalone | ||
| 70 | + `ObuKind::TileGroup(Vec<Tile>)` OBUs) is not collected at all today — | ||
| 71 | + `decode_stream`'s `while pos < data.len()` loop only matches | ||
| 72 | + `ObuKind::Frame`/`FrameHeader` (for `show_existing_frame`) and silently | ||
| 73 | + `continue`s past everything else, including a bare `TileGroup` OBU. | ||
| 74 | + | ||
| 75 | +No gate was added — the charter's mandatory gate asserts a tile-firing | ||
| 76 | +counter `> 1` on real decoded output, which requires part 1 (entropy per | ||
| 77 | +tile) to exist first; writing the gate against the untouched refusal would | ||
| 78 | +either be vacuous or fail immediately. | ||
| 79 | + | ||
| 80 | +## Remaining refusal strings (verbatim, unchanged) | ||
| 81 | +- `"a frame with more than one tile (this decoder only ever decodes tile 0)"` | ||
| 82 | + — `stream.rs:294-296`, still fires for every `tile_info.cols > 1 || | ||
| 83 | + tile_info.rows > 1` frame, intra or inter. | ||
| 84 | + | ||
| 85 | +## Verification | ||
| 86 | +`cargo test -p ec-av1 --lib` (`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-tiles`, | ||
| 87 | +`EC_AV1_REQUIRE_AOMENC=1`): 232 passed, 0 failed, 17 ignored, 174.28s — | ||
| 88 | +baseline unchanged, no regression from the groundwork commit. | ||
| 89 | + | ||
| 90 | +## Next lever (for whoever picks this up) | ||
| 91 | +Land in the charter's own staged order, each its own commit: | ||
| 92 | +1. Restructure `decode_key_frame_tile_with_cdfs` to accept | ||
| 93 | + `tiles: &[(u32 /* tile_num */, &[u8])]` + `&TileInfo` in place of a | ||
| 94 | + single `data: &[u8]`, wrap the existing SB double loop (currently | ||
| 95 | + `decode.rs` lines ~4547 header `for sb_r in 0..sb_rows` through its | ||
| 96 | + matching close ~4947) in `for &(tile_num, bytes) in tiles`, call | ||
| 97 | + `neighbours.start_tile(...)` (already written, unused) and set | ||
| 98 | + `PlaneBuf` tile pixel origins (not yet added) at each tile's start, | ||
| 99 | + narrow the sb range, and capture `cdfs` as the returned table only when | ||
| 100 | + `tile_num == tile_info.context_update_tile_id`. Update the one caller | ||
| 101 | + (`decode_key_frame_tile`, `decode.rs:4478`) and `stream.rs`'s key-frame | ||
| 102 | + branch to build the tile list instead of `tiles.first()`. Prove stage 1 | ||
| 103 | + (two tiles, column split, all-intra) before touching anything else. | ||
| 104 | +2. Same restructuring for `decode_inter_frame_tile_with_cdfs`, PLUS | ||
| 105 | + threading `tile_row0_mi`/`tile_col0_mi` into `find_mv_stack_with_sign_bias` | ||
| 106 | + and `find_samples`/`num_proj_ref` (both currently frame-relative-only). | ||
| 107 | +3. Multi-tile-group OBU collection in `decode_stream`'s main loop | ||
| 108 | + (`ObuKind::FrameHeader` + trailing `ObuKind::TileGroup` accumulation | ||
| 109 | + before dispatch, mirroring the existing `pending: Option<FrameHeader>` | ||
| 110 | + field already on `Av1Parser` internally, though that field is private — | ||
| 111 | + check whether it's exposed or the collection has to happen in | ||
| 112 | + `decode_stream` itself against raw OBU events). | ||
| 113 | +4. `context_update_tile_id != 0` pin test once tables save correctly. | ||
| 114 | +5. The mandatory gate: `--tile-columns=1 --tile-rows=1` aomenc recipe | ||
| 115 | + (log2 values), thread-local `TILE_HITS` counter (not yet added) | ||
| 116 | + incremented once per tile actually decoded, hard-asserted `> 1`. | ||