Decode the 16x16-level 1:4 partition -- four 16x4/4x16 strips with paired 4:2:0 chroma
Browse files at this commitb1f19e618ddbc7b73aa356c6064cc7f61b1e4c84Parent: 31ae209- feat
- decode the 16x16-level 1:4 partition -- four 16x4/4x16 strips with paired 4:2:0 chroma
5 changed files +676 -14
- crates/ec-av1/src/cdf.rs +7 -1
- crates/ec-av1/src/cdf_state.rs +41 -1
- crates/ec-av1/src/decode.rs +404 -11
- crates/ec-av1/src/refusal_inventory.rs +2 -1
- crates/ec-av1/src/stream.rs +222 -0
crates/ec-av1/src/cdf.rsmodified+7 -1
| @@ -477,7 +477,7 @@ pub const CFL_SIGN: [u16; 9] = [1418, 2123, 13340, 18405, 26972, 28343, 32294, 3 | |||
| 477 | /// `av1_filter_intra_allowed_bsize`'s "both sides <= 32" bound, so libaom | 477 | /// `av1_filter_intra_allowed_bsize`'s "both sides <= 32" bound, so libaom |
| 478 | /// reads `use_filter_intra` there too and the missing rows dropped the | 478 | /// reads `use_filter_intra` there too and the missing rows dropped the |
| 479 | /// symbol on every DC_PRED 1:4 strip. | 479 | /// symbol on every DC_PRED 1:4 strip. |
| 480 | -pub const FILTER_INTRA: [[u16; 3]; 12] = [ | 480 | +pub const FILTER_INTRA: [[u16; 3]; 14] = [ |
| 481 | [4621, 32768, 0], | 481 | [4621, 32768, 0], |
| 482 | [7866, 32768, 0], | 482 | [7866, 32768, 0], |
| 483 | [12408, 32768, 0], | 483 | [12408, 32768, 0], |
| @@ -490,6 +490,12 @@ pub const FILTER_INTRA: [[u16; 3]; 12] = [ | |||
| 490 | [5893, 32768, 0], | 490 | [5893, 32768, 0], |
| 491 | [18101, 32768, 0], | 491 | [18101, 32768, 0], |
| 492 | [20229, 32768, 0], | 492 | [20229, 32768, 0], |
| 493 | + // lane-r14: the 16x16-level 1:4 pair (`default_filter_intra_cdfs` index | ||
| 494 | + // 17/16 -- BLOCK_16X4/BLOCK_4X16, generated by | ||
| 495 | + // `scripts/extract-filter-intra-cdfs.py`), classes 12/13. Both sides <= 32, | ||
| 496 | + // so libaom writes `use_filter_intra` on every DC_PRED strip of this shape. | ||
| 497 | + [10368, 32768, 0], | ||
| 498 | + [12770, 32768, 0], | ||
| 493 | ]; | 499 | ]; |
| 494 | /// `default_filter_intra_mode_cdf` (entropymode.c): which of the five | 500 | /// `default_filter_intra_mode_cdf` (entropymode.c): which of the five |
| 495 | /// `FILTER_INTRA_MODES` a `use_filter_intra` block picks. | 501 | /// `FILTER_INTRA_MODES` a `use_filter_intra` block picks. |
crates/ec-av1/src/cdf_state.rsmodified+41 -1
| @@ -186,6 +186,22 @@ pub(crate) enum TxbSet { | |||
| 186 | /// `tx_size_sqr == TX_4X4`, intra returns `EXT_TX_SET_DTT4_IDTX_1DDCT`, | 186 | /// `tx_size_sqr == TX_4X4`, intra returns `EXT_TX_SET_DTT4_IDTX_1DDCT`, |
| 187 | /// the same seven-symbol set (and same `TX_4X4` row) `Luma4Set1` reads. | 187 | /// the same seven-symbol set (and same `TX_4X4` row) `Luma4Set1` reads. |
| 188 | LumaRect4x8Set1, | 188 | LumaRect4x8Set1, |
| 189 | + /// The luma 16x4/4x16 transform of a 16x16-level `PARTITION_HORZ_4`/ | ||
| 190 | + /// `PARTITION_VERT_4` strip (lane-r14). `get_txsize_entropy_ctx` | ||
| 191 | + /// ((`txsize_sqr_map` + `txsize_sqr_up_map` + 1) >> 1) resolves `TX_16X4` | ||
| 192 | + /// to `TX_8X8`, and the transform has 64 coded positions, so EVERY table | ||
| 193 | + /// here is [`Luma8`](TxbSet::Luma8)'s (`eob_pt_64` included) except | ||
| 194 | + /// `tx_type`: `read_tx_type` indexes `intra_ext_tx_cdf[eset] | ||
| 195 | + /// [txsize_sqr_map[TX_16X4]]` = the `TX_4X4` row, and | ||
| 196 | + /// `av1_get_ext_tx_set_type` at `tx_size_sqr_up == TX_16X16` with | ||
| 197 | + /// `tx_size_sqr == TX_4X4` returns `EXT_TX_SET_DTT4_IDTX` under | ||
| 198 | + /// `reduced_tx_set` -- the same pair [`LumaRect4x8`](TxbSet::LumaRect4x8) | ||
| 199 | + /// reads, which differs from this variant only in its 32-position `eob_pt`. | ||
| 200 | + LumaRect16x4, | ||
| 201 | + /// [`LumaRect16x4`](TxbSet::LumaRect16x4)'s `reduced_tx_set: false` | ||
| 202 | + /// counterpart: `EXT_TX_SET_DTT4_IDTX_1DDCT`, the seven-symbol `TX_4X4` | ||
| 203 | + /// row [`LumaRect4x8Set1`](TxbSet::LumaRect4x8Set1) reads. | ||
| 204 | + LumaRect16x4Set1, | ||
| 189 | } | 205 | } |
| 190 | 206 | ||
| 191 | /// The tables one transform block is coded with, borrowed from the state for | 207 | /// The tables one transform block is coded with, borrowed from the state for |
| @@ -541,7 +557,7 @@ pub(crate) struct Cdfs { | |||
| 541 | /// `[1]`=8x8, `[2]`=16x16, `[3]`=32x32, `[4]`=32x16, `[5]`=16x32, | 557 | /// `[1]`=8x8, `[2]`=16x16, `[3]`=32x32, `[4]`=32x16, `[5]`=16x32, |
| 542 | /// `[6]`=16x8, `[7]`=8x16, `[8]`=4x8, `[9]`=8x4, `[10]`=32x8, `[11]`=8x32) -- | 558 | /// `[6]`=16x8, `[7]`=8x16, `[8]`=4x8, `[9]`=8x4, `[10]`=32x8, `[11]`=8x32) -- |
| 543 | /// see [`cdf::FILTER_INTRA`]. | 559 | /// see [`cdf::FILTER_INTRA`]. |
| 544 | - pub filter_intra: [[u16; 3]; 12], | 560 | + pub filter_intra: [[u16; 3]; 14], |
| 545 | /// Which `FILTER_INTRA_MODES` entry a `use_filter_intra` block picks. | 561 | /// Which `FILTER_INTRA_MODES` entry a `use_filter_intra` block picks. |
| 546 | pub filter_intra_mode: [u16; 6], | 562 | pub filter_intra_mode: [u16; 6], |
| 547 | /// `TxMode::Select`'s `tx_depth` flag at an 8x8 block, by `tx_size_context` | 563 | /// `TxMode::Select`'s `tx_depth` flag at an 8x8 block, by `tx_size_context` |
| @@ -1767,6 +1783,30 @@ impl Cdfs { | |||
| 1767 | tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()), | 1783 | tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()), |
| 1768 | eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1), | 1784 | eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1), |
| 1769 | }, | 1785 | }, |
| 1786 | + TxbSet::LumaRect16x4 => TxbTables { | ||
| 1787 | + side: 8, | ||
| 1788 | + txb_skip: &mut self.txb_skip_luma_8, | ||
| 1789 | + eob_pt: &mut self.eob_pt_64_luma, | ||
| 1790 | + eob_extra: &mut self.eob_extra_luma_8, | ||
| 1791 | + base: &mut self.base_luma_8, | ||
| 1792 | + base_eob: &mut self.base_eob_luma_8, | ||
| 1793 | + br: &mut self.br_luma_8, | ||
| 1794 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1795 | + tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()), | ||
| 1796 | + eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), | ||
| 1797 | + }, | ||
| 1798 | + TxbSet::LumaRect16x4Set1 => TxbTables { | ||
| 1799 | + side: 8, | ||
| 1800 | + txb_skip: &mut self.txb_skip_luma_8, | ||
| 1801 | + eob_pt: &mut self.eob_pt_64_luma, | ||
| 1802 | + eob_extra: &mut self.eob_extra_luma_8, | ||
| 1803 | + base: &mut self.base_luma_8, | ||
| 1804 | + base_eob: &mut self.base_eob_luma_8, | ||
| 1805 | + br: &mut self.br_luma_8, | ||
| 1806 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1807 | + tx_type: Some(self.intra_tx_type_4_set1[mode].as_mut_slice()), | ||
| 1808 | + eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), | ||
| 1809 | + }, | ||
| 1770 | TxbSet::ChromaRect8x4 => TxbTables { | 1810 | TxbSet::ChromaRect8x4 => TxbTables { |
| 1771 | side: 8, | 1811 | side: 8, |
| 1772 | txb_skip: &mut self.txb_skip_chroma_8, | 1812 | txb_skip: &mut self.txb_skip_chroma_8, |
crates/ec-av1/src/decode.rsmodified+404 -11
| @@ -1952,6 +1952,27 @@ pub(crate) fn rect4_coeff_hits() -> usize { | |||
| 1952 | RECT4_COEFF_HITS.with(|c| c.get()) | 1952 | RECT4_COEFF_HITS.with(|c| c.get()) |
| 1953 | } | 1953 | } |
| 1954 | 1954 | ||
| 1955 | +// lane-r14: the 16x16-level 1:4 pair -- four 16x4 (`PARTITION_HORZ_4`) or | ||
| 1956 | +// 4x16 (`PARTITION_VERT_4`) strips, `CHROMA` counting the odd strips that | ||
| 1957 | +// close a 4:2:0 chroma pair and `COEFF` the strips with a coded residual. | ||
| 1958 | +thread_local! { | ||
| 1959 | + static RECT4_16_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1960 | + static RECT4_16_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1961 | + static RECT4_16_CHROMA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1962 | + static RECT4_16_COEFF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1963 | +} | ||
| 1964 | + | ||
| 1965 | +/// Current values of the 16x16-level 1:4 counters: `(16x4 strips, 4x16 | ||
| 1966 | +/// strips, chroma-reference strips, strips with a coded residual)`. | ||
| 1967 | +pub fn rect4_16_counters() -> (usize, usize, usize, usize) { | ||
| 1968 | + ( | ||
| 1969 | + RECT4_16_HORZ_HITS.with(|c| c.get()), | ||
| 1970 | + RECT4_16_VERT_HITS.with(|c| c.get()), | ||
| 1971 | + RECT4_16_CHROMA_HITS.with(|c| c.get()), | ||
| 1972 | + RECT4_16_COEFF_HITS.with(|c| c.get()), | ||
| 1973 | + ) | ||
| 1974 | +} | ||
| 1975 | + | ||
| 1955 | /// Current value of `RECT4_32_HORZ_HITS` (32x8 strips decoded). | 1976 | /// Current value of `RECT4_32_HORZ_HITS` (32x8 strips decoded). |
| 1956 | pub(crate) fn rect4_32_horz_hits() -> usize { | 1977 | pub(crate) fn rect4_32_horz_hits() -> usize { |
| 1957 | RECT4_32_HORZ_HITS.with(|c| c.get()) | 1978 | RECT4_32_HORZ_HITS.with(|c| c.get()) |
| @@ -4667,6 +4688,10 @@ fn filter_intra_size_class_rect(bw: usize, bh: usize) -> Option<usize> { | |||
| 4667 | // tile (class symbol-consumption-gap). | 4688 | // tile (class symbol-consumption-gap). |
| 4668 | (32, 8) => Some(10), | 4689 | (32, 8) => Some(10), |
| 4669 | (8, 32) => Some(11), | 4690 | (8, 32) => Some(11), |
| 4691 | + // lane-r14: the 16x16-level 1:4 pair (`decode_rect4_16`'s 16x4/4x16 | ||
| 4692 | + // strips), rows 17/16 of `default_filter_intra_cdfs`. | ||
| 4693 | + (16, 4) => Some(12), | ||
| 4694 | + (4, 16) => Some(13), | ||
| 4670 | _ if bw == bh => filter_intra_size_class(bw), | 4695 | _ if bw == bh => filter_intra_size_class(bw), |
| 4671 | _ => None, | 4696 | _ => None, |
| 4672 | } | 4697 | } |
| @@ -4692,7 +4717,13 @@ fn palette_bsize_ctx(side: usize) -> Option<usize> { | |||
| 4692 | /// `trailing_zeros` is `log2` exactly. `None` past `av1_allow_palette`'s own | 4717 | /// `trailing_zeros` is `log2` exactly. `None` past `av1_allow_palette`'s own |
| 4693 | /// bound (`block_size_wide/high <= 64`, `sb_type >= BLOCK_8X8`). | 4718 | /// bound (`block_size_wide/high <= 64`, `sb_type >= BLOCK_8X8`). |
| 4694 | fn palette_bsize_ctx_wh(bw: usize, bh: usize) -> Option<usize> { | 4719 | fn palette_bsize_ctx_wh(bw: usize, bh: usize) -> Option<usize> { |
| 4695 | - if !(8..=64).contains(&bw) || !(8..=64).contains(&bh) { | 4720 | + // lane-r14: `av1_allow_palette`'s bound is `sb_type >= BLOCK_8X8` by the |
| 4721 | + // BLOCK_SIZES_ALL enum INDEX, which the 1:4 shapes BLOCK_4X16 (16) and | ||
| 4722 | + // BLOCK_16X4 (17) clear -- a 64-pixel block, so `av1_get_palette_bsize_ctx` | ||
| 4723 | + // (`num_pels_log2 - num_pels_log2[BLOCK_8X8]`) is 0 for them, exactly as | ||
| 4724 | + // for an 8x8. Reading the dimension bound as "both sides >= 8" dropped | ||
| 4725 | + // `palette_y_mode` on every 16x4/4x16 strip of a screen-content frame. | ||
| 4726 | + if bw > 64 || bh > 64 || bw * bh < 64 { | ||
| 4696 | return None; | 4727 | return None; |
| 4697 | } | 4728 | } |
| 4698 | Some(((bw * bh) as u32).trailing_zeros() as usize - 6) | 4729 | Some(((bw * bh) as u32).trailing_zeros() as usize - 6) |
| @@ -5014,6 +5045,12 @@ fn read_intra_mode_rect( | |||
| 5014 | above_mode: usize, | 5045 | above_mode: usize, |
| 5015 | left_mode: usize, | 5046 | left_mode: usize, |
| 5016 | cfl: bool, | 5047 | cfl: bool, |
| 5048 | + // lane-r14: `is_chroma_reference` -- false only for a strip one mi tall | ||
| 5049 | + // (or wide) that is NOT the odd one of its 4:2:0 pair, where libaom reads | ||
| 5050 | + // no `uv_mode`/`cfl_alpha`/`angle_delta_uv`/`palette_uv` at all (the pair's | ||
| 5051 | + // chroma is coded once, on the closing strip). Every other caller is a | ||
| 5052 | + // block big enough to own its chroma and passes `true`. | ||
| 5053 | + has_chroma: bool, | ||
| 5017 | bw: usize, | 5054 | bw: usize, |
| 5018 | bh: usize, | 5055 | bh: usize, |
| 5019 | enable_filter_intra: bool, | 5056 | enable_filter_intra: bool, |
| @@ -5077,21 +5114,23 @@ fn read_intra_mode_rect( | |||
| 5077 | 0 | 5114 | 0 |
| 5078 | }; | 5115 | }; |
| 5079 | istep!("angle_y", angle_delta_y); | 5116 | istep!("angle_y", angle_delta_y); |
| 5080 | - let uv_mode = if cfl { | 5117 | + let uv_mode = if !has_chroma { |
| 5118 | + DC_PRED | ||
| 5119 | + } else if cfl { | ||
| 5081 | dec.symbol(&mut cdfs.uv_mode_cfl[mode]) | 5120 | dec.symbol(&mut cdfs.uv_mode_cfl[mode]) |
| 5082 | } else { | 5121 | } else { |
| 5083 | dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) | 5122 | dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) |
| 5084 | }; | 5123 | }; |
| 5085 | istep!("uv_mode", uv_mode as i32); | 5124 | istep!("uv_mode", uv_mode as i32); |
| 5086 | - let alpha = if cfl && uv_mode == UV_CFL_PRED { | 5125 | + let alpha = if has_chroma && cfl && uv_mode == UV_CFL_PRED { |
| 5087 | Some(read_cfl_alphas(dec, cdfs)) | 5126 | Some(read_cfl_alphas(dec, cdfs)) |
| 5088 | } else { | 5127 | } else { |
| 5089 | None | 5128 | None |
| 5090 | }; | 5129 | }; |
| 5091 | - if (9..=12).contains(&uv_mode) { | 5130 | + if has_chroma && (9..=12).contains(&uv_mode) { |
| 5092 | SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1)); | 5131 | SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1)); |
| 5093 | } | 5132 | } |
| 5094 | - let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) { | 5133 | + let angle_delta_uv = if has_chroma && (V_PRED..=D67_PRED).contains(&uv_mode) { |
| 5095 | DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1)); | 5134 | DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1)); |
| 5096 | read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED]) | 5135 | read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED]) |
| 5097 | } else { | 5136 | } else { |
| @@ -5131,7 +5170,11 @@ fn read_intra_mode_rect( | |||
| 5131 | palette_y_pending = Some((n, colors)); | 5170 | palette_y_pending = Some((n, colors)); |
| 5132 | } | 5171 | } |
| 5133 | let palette_uv_mode_ctx = usize::from(use_palette_y); | 5172 | let palette_uv_mode_ctx = usize::from(use_palette_y); |
| 5134 | - if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[palette_uv_mode_ctx]) != 0 { | 5173 | + // `read_palette_mode_info`'s own `xd->is_chroma_ref` guard. |
| 5174 | + if has_chroma | ||
| 5175 | + && uv_mode == DC_PRED | ||
| 5176 | + && dec.symbol(&mut cdfs.palette_uv_mode[palette_uv_mode_ctx]) != 0 | ||
| 5177 | + { | ||
| 5135 | let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]); | 5178 | let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]); |
| 5136 | let (u_colors, v_colors) = read_palette_colors_uv(dec, n, palette_uv_cache); | 5179 | let (u_colors, v_colors) = read_palette_colors_uv(dec, n, palette_uv_cache); |
| 5137 | palette_uv_pending = Some((n, u_colors, v_colors)); | 5180 | palette_uv_pending = Some((n, u_colors, v_colors)); |
| @@ -5687,6 +5730,7 @@ fn decode_block_rect( | |||
| 5687 | nb_above_mode, | 5730 | nb_above_mode, |
| 5688 | nb_left_mode, | 5731 | nb_left_mode, |
| 5689 | true, | 5732 | true, |
| 5733 | + true, | ||
| 5690 | bw, | 5734 | bw, |
| 5691 | bh, | 5735 | bh, |
| 5692 | enable_filter_intra, | 5736 | enable_filter_intra, |
| @@ -6161,6 +6205,7 @@ fn decode_leaf_rect( | |||
| 6161 | above_mode, | 6205 | above_mode, |
| 6162 | left_mode, | 6206 | left_mode, |
| 6163 | true, | 6207 | true, |
| 6208 | + true, | ||
| 6164 | bw, | 6209 | bw, |
| 6165 | bh, | 6210 | bh, |
| 6166 | enable_filter_intra, | 6211 | enable_filter_intra, |
| @@ -6440,6 +6485,7 @@ fn decode_block_rect4( | |||
| 6440 | above_mode, | 6485 | above_mode, |
| 6441 | left_mode, | 6486 | left_mode, |
| 6442 | true, | 6487 | true, |
| 6488 | + true, | ||
| 6443 | bw, | 6489 | bw, |
| 6444 | bh, | 6490 | bh, |
| 6445 | enable_filter_intra, | 6491 | enable_filter_intra, |
| @@ -6741,6 +6787,332 @@ fn decode_block_rect4( | |||
| 6741 | Ok((mode, uv_predict_mode)) | 6787 | Ok((mode, uv_predict_mode)) |
| 6742 | } | 6788 | } |
| 6743 | 6789 | ||
| 6790 | +/// Decodes the four 16x4 / 4x16 strips of a 16x16-level `PARTITION_HORZ_4` / | ||
| 6791 | +/// `PARTITION_VERT_4` (lane-r14) -- [`decode_block_rect4`]'s pair one level | ||
| 6792 | +/// down, and the first shape here whose luma block is a single mi row (or | ||
| 6793 | +/// column). | ||
| 6794 | +/// | ||
| 6795 | +/// What is new at this size is CHROMA. `is_chroma_reference` | ||
| 6796 | +/// (`av1_common_int.h`) is false for a 4:2:0 block one mi tall (wide) on an | ||
| 6797 | +/// EVEN mi row (column), so strips 0 and 2 read no `uv_mode`/`cfl_alpha`/ | ||
| 6798 | +/// `angle_delta_uv` at all and code no chroma residual; strips 1 and 3 close | ||
| 6799 | +/// the pair and carry the chroma of the whole 16x8 (8x16) luma pair -- | ||
| 6800 | +/// `setup_pred_plane`'s own `if (subsampling_y && (mi_row & 1) && | ||
| 6801 | +/// mi_size_high[bsize] == 1) mi_row -= 1` offset, i.e. an 8x4 (4x8) chroma | ||
| 6802 | +/// transform at the PAIR's origin, with CfL averaging over the pair's luma. | ||
| 6803 | +/// | ||
| 6804 | +/// Tables: LUMA `TX_16X4`/`TX_4X16` averages to the 8x8 entropy context | ||
| 6805 | +/// ((0 + 2 + 1) >> 1 = 1) with 64 coded positions, so its CDF set is | ||
| 6806 | +/// [`TxbSet::LumaRect16x4`] (`Luma8`'s tables, the `TX_4X4` `tx_type` row); | ||
| 6807 | +/// scans are [`SCAN_16X4`]/[`SCAN_4X16`]. CHROMA `TX_8X4`/`TX_4X8` is | ||
| 6808 | +/// [`TxbSet::ChromaRect8x4`] with [`SCAN_8X4`]/[`SCAN_4X8`]. Angle deltas ARE | ||
| 6809 | +/// coded (`av1_use_angle_delta` compares the BLOCK_SIZES_ALL enum index, and | ||
| 6810 | +/// BLOCK_16X4 is 17), and so is `use_filter_intra` (both sides <= 32) off this | ||
| 6811 | +/// shape's own CDF row. | ||
| 6812 | +/// | ||
| 6813 | +/// A split transform (`tx_depth != 0`, `sub_tx_size_map[TX_16X4] == TX_8X4`) | ||
| 6814 | +/// refuses by name rather than guess-decode. | ||
| 6815 | +#[allow(clippy::too_many_arguments)] | ||
| 6816 | +fn decode_rect4_16( | ||
| 6817 | + dec: &mut SymbolDecoder, | ||
| 6818 | + cdfs: &mut Cdfs, | ||
| 6819 | + neighbours: &mut Neighbours, | ||
| 6820 | + at16: (usize, usize), | ||
| 6821 | + horz: bool, | ||
| 6822 | + y: &mut PlaneBuf, | ||
| 6823 | + u: &mut PlaneBuf, | ||
| 6824 | + v: &mut PlaneBuf, | ||
| 6825 | + enable_filter_intra: bool, | ||
| 6826 | + allow_screen_content_tools: bool, | ||
| 6827 | + base_q_idx: u8, | ||
| 6828 | + tx_select: bool, | ||
| 6829 | + reduced_tx_set: bool, | ||
| 6830 | +) -> Result<()> { | ||
| 6831 | + let _ = base_q_idx; | ||
| 6832 | + let (r, c) = at16; | ||
| 6833 | + let (mi_row0, mi_col0) = (r * (SUB / MI), c * (SUB / MI)); | ||
| 6834 | + let (bw, bh) = if horz { (16, 4) } else { (4, 16) }; | ||
| 6835 | + let (mi_w, mi_h) = (bw / MI, bh / MI); | ||
| 6836 | + let scan: &[u16] = if horz { &SCAN_16X4 } else { &SCAN_4X16 }; | ||
| 6837 | + let chroma_scan: &[u16] = if horz { &SCAN_8X4 } else { &SCAN_4X8 }; | ||
| 6838 | + let mut prev: Option<((usize, usize), usize)> = None; | ||
| 6839 | + let mut last_mode = DC_PRED; | ||
| 6840 | + let mut last_uv_mode = DC_PRED; | ||
| 6841 | + for i in 0..4usize { | ||
| 6842 | + let lmi = if horz { | ||
| 6843 | + (mi_row0 + i, mi_col0) | ||
| 6844 | + } else { | ||
| 6845 | + (mi_row0, mi_col0 + i) | ||
| 6846 | + }; | ||
| 6847 | + let has_chroma = i % 2 == 1; | ||
| 6848 | + // `decode_block_rect4`'s own neighbour rule: the coarse 16-px cell | ||
| 6849 | + // aliases all four strips onto one entry, so the mi-exact map wins and | ||
| 6850 | + // the previous strip stands in on the split axis. | ||
| 6851 | + let mut above_mode = neighbours.above_mode[c]; | ||
| 6852 | + let mut left_mode = neighbours.left_mode[r]; | ||
| 6853 | + if let Some(((pr, pc), pmode)) = prev { | ||
| 6854 | + if pc == lmi.1 && lmi.0 == pr + mi_h { | ||
| 6855 | + above_mode = pmode; | ||
| 6856 | + } else if pr == lmi.0 && lmi.1 == pc + mi_w { | ||
| 6857 | + left_mode = pmode; | ||
| 6858 | + } | ||
| 6859 | + } | ||
| 6860 | + let (above_mode, left_mode) = | ||
| 6861 | + neighbours.modes_above_left_mi(lmi.0, lmi.1, (above_mode, left_mode)); | ||
| 6862 | + let ( | ||
| 6863 | + skip, | ||
| 6864 | + mode, | ||
| 6865 | + angle_delta_y, | ||
| 6866 | + uv_mode, | ||
| 6867 | + angle_delta_uv, | ||
| 6868 | + alpha, | ||
| 6869 | + filter_intra, | ||
| 6870 | + palette_y, | ||
| 6871 | + palette_uv, | ||
| 6872 | + ) = read_intra_mode_rect( | ||
| 6873 | + dec, | ||
| 6874 | + cdfs, | ||
| 6875 | + above_mode, | ||
| 6876 | + left_mode, | ||
| 6877 | + true, | ||
| 6878 | + has_chroma, | ||
| 6879 | + bw, | ||
| 6880 | + bh, | ||
| 6881 | + enable_filter_intra, | ||
| 6882 | + neighbours.skip_txfm_ctx(lmi.0, lmi.1), | ||
| 6883 | + allow_screen_content_tools, | ||
| 6884 | + None, | ||
| 6885 | + &[], | ||
| 6886 | + lmi.0, | ||
| 6887 | + lmi.1, | ||
| 6888 | + )?; | ||
| 6889 | + if palette_y.is_some() || palette_uv.is_some() { | ||
| 6890 | + return Err(unsupported( | ||
| 6891 | + "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", | ||
| 6892 | + )); | ||
| 6893 | + } | ||
| 6894 | + let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); | ||
| 6895 | + if smooth_neighbor { | ||
| 6896 | + SMOOTH_LUMA_HITS.with(|h| h.set(h.get() + 1)); | ||
| 6897 | + } | ||
| 6898 | + if filter_intra.is_some() { | ||
| 6899 | + FILTER_INTRA_RECT_HITS.with(|h| h.set(h.get() + 1)); | ||
| 6900 | + } | ||
| 6901 | + // `bsize_to_tx_size_cat(BLOCK_16X4)`: `max_txsize_rect_lookup` is | ||
| 6902 | + // TX_16X4 and `sub_tx_size_map` reaches TX_4X4 in two steps, so the | ||
| 6903 | + // depth symbol is the 3-symbol `tx_size_cat1` -- not the 2-symbol | ||
| 6904 | + // `cat0` a 4x8 leaf reads nor the `cat2` a 32x8 strip does. | ||
| 6905 | + let depth = if tx_select { | ||
| 6906 | + let ctx = tx_size_context_rect(neighbours, lmi, bw, bh); | ||
| 6907 | + dec.symbol(&mut cdfs.tx_size_cat1[ctx]) | ||
| 6908 | + } else { | ||
| 6909 | + 0 | ||
| 6910 | + }; | ||
| 6911 | + if depth != 0 { | ||
| 6912 | + TX_DEPTH_HITS.with(|h| h.set(h.get() + 1)); | ||
| 6913 | + return Err(unsupported( | ||
| 6914 | + "a 16x4/4x16 strip whose transform is split (sub_tx_size_map[TX_16X4] == TX_8X4; the per-unit walk is not ported at this shape)", | ||
| 6915 | + )); | ||
| 6916 | + } | ||
| 6917 | + let (px, py) = (lmi.1 * MI, lmi.0 * MI); | ||
| 6918 | + let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); | ||
| 6919 | + let levels = if skip { | ||
| 6920 | + let zeros = vec![0i32; bw * bh]; | ||
| 6921 | + y.reconstruct_rect( | ||
| 6922 | + px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra, | ||
| 6923 | + smooth_neighbor, | ||
| 6924 | + ); | ||
| 6925 | + zeros | ||
| 6926 | + } else { | ||
| 6927 | + // The strip's luma TU *is* the strip (`plane_bsize == | ||
| 6928 | + // txsize_to_bsize[tx_size]`), so `get_txb_ctx` fixes | ||
| 6929 | + // `txb_skip_ctx` at 0. | ||
| 6930 | + let around = neighbours.around_mi_rect(lmi, bw, bh)[0]; | ||
| 6931 | + let set = if reduced_tx_set { | ||
| 6932 | + TxbSet::LumaRect16x4 | ||
| 6933 | + } else { | ||
| 6934 | + TxbSet::LumaRect16x4Set1 | ||
| 6935 | + }; | ||
| 6936 | + let mut coding = cdfs.txb(set, fi_tx_row(mode, filter_intra)); | ||
| 6937 | + let (levels, tx_type) = read_coeffs_rect( | ||
| 6938 | + dec, | ||
| 6939 | + &mut coding, | ||
| 6940 | + scan, | ||
| 6941 | + bw, | ||
| 6942 | + bh, | ||
| 6943 | + 0, | ||
| 6944 | + dc_sign_ctx(around.2), | ||
| 6945 | + TxType::DctDct, | ||
| 6946 | + )?; | ||
| 6947 | + let residual = dequant_and_inverse_typed_wh( | ||
| 6948 | + &levels, | ||
| 6949 | + bw, | ||
| 6950 | + bh, | ||
| 6951 | + crate::decode::bit_depth(), | ||
| 6952 | + block_q_idx(), | ||
| 6953 | + plane_q_delta(0).0, | ||
| 6954 | + plane_q_delta(0).1, | ||
| 6955 | + tx_type, | ||
| 6956 | + ); | ||
| 6957 | + y.reconstruct_rect( | ||
| 6958 | + px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra, | ||
| 6959 | + smooth_neighbor, | ||
| 6960 | + ); | ||
| 6961 | + RECT4_16_COEFF_HITS.with(|h| h.set(h.get() + 1)); | ||
| 6962 | + levels | ||
| 6963 | + }; | ||
| 6964 | + neighbours.record_mode_mi(lmi.0, lmi.1, mi_w, mi_h, mode); | ||
| 6965 | + neighbours.record_mi_luma_rect(lmi, bw, bh, &levels); | ||
| 6966 | + neighbours.fill_skip_grid_rect(lmi, mi_w, mi_h, skip); | ||
| 6967 | + neighbours.fill_lf_grid_rect(lmi, mi_w, mi_h, bw as u8, bh as u8, 0); | ||
| 6968 | + // `update_partition_context` writes `partition_context_lookup[ | ||
| 6969 | + // BLOCK_16X4]` over the whole 16x16: full width above, a 4-px side on | ||
| 6970 | + // the left (mirrored under VERT_4). | ||
| 6971 | + for cell in 0..mi_w { | ||
| 6972 | + if let Some(slot) = neighbours.above_side_mi.get_mut(lmi.1 + cell) { | ||
| 6973 | + *slot = bw; | ||
| 6974 | + } | ||
| 6975 | + } | ||
| 6976 | + for cell in 0..mi_h { | ||
| 6977 | + if let Some(slot) = neighbours.left_side_mi.get_mut(lmi.0 + cell) { | ||
| 6978 | + *slot = bh; | ||
| 6979 | + } | ||
| 6980 | + } | ||
| 6981 | + if has_chroma { | ||
| 6982 | + RECT4_16_CHROMA_HITS.with(|h| h.set(h.get() + 1)); | ||
| 6983 | + let pair_mi = if horz { | ||
| 6984 | + (lmi.0 - 1, lmi.1) | ||
| 6985 | + } else { | ||
| 6986 | + (lmi.0, lmi.1 - 1) | ||
| 6987 | + }; | ||
| 6988 | + let (pw, ph) = if horz { (16, 8) } else { (8, 16) }; | ||
| 6989 | + let (ppx, ppy) = (pair_mi.1 * MI, pair_mi.0 * MI); | ||
| 6990 | + let (cpx, cpy) = (ppx / 2, ppy / 2); | ||
| 6991 | + let (cw, ch) = (pw / 2, ph / 2); | ||
| 6992 | + let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; | ||
| 6993 | + let pair_reach = Reach::of_rect(pw, ph, ppx, ppy, y.width, y.height); | ||
| 6994 | + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c); | ||
| 6995 | + let (u_levels, v_levels) = if skip { | ||
| 6996 | + let zeros = vec![0i32; cw * ch]; | ||
| 6997 | + for (buf, _plane) in [(&mut *u, 1usize), (&mut *v, 2)] { | ||
| 6998 | + buf.reconstruct_rect( | ||
| 6999 | + cpx, | ||
| 7000 | + cpy, | ||
| 7001 | + cw, | ||
| 7002 | + ch, | ||
| 7003 | + uv_predict_mode, | ||
| 7004 | + angle_delta_uv, | ||
| 7005 | + pair_reach, | ||
| 7006 | + &zeros, | ||
| 7007 | + None, | ||
| 7008 | + None, | ||
| 7009 | + smooth_neighbor_uv, | ||
| 7010 | + ); | ||
| 7011 | + } | ||
| 7012 | + (zeros.clone(), zeros) | ||
| 7013 | + } else { | ||
| 7014 | + let around = neighbours.around_mi_rect(pair_mi, pw, ph); | ||
| 7015 | + let mut planes = Vec::with_capacity(2); | ||
| 7016 | + for plane in 1..3 { | ||
| 7017 | + let default_tx = default_intra_tx_type(uv_predict_mode as u8); | ||
| 7018 | + let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1); | ||
| 7019 | + let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); | ||
| 7020 | + let (levels, tx_type) = read_coeffs_rect( | ||
| 7021 | + dec, | ||
| 7022 | + &mut coding, | ||
| 7023 | + chroma_scan, | ||
| 7024 | + cw, | ||
| 7025 | + ch, | ||
| 7026 | + skip_ctx, | ||
| 7027 | + dc_sign_ctx(around[plane].2), | ||
| 7028 | + default_tx, | ||
| 7029 | + )?; | ||
| 7030 | + planes.push((levels, tx_type)); | ||
| 7031 | + } | ||
| 7032 | + let (v_levels, v_tx_type) = planes.pop().expect("plane 2"); | ||
| 7033 | + let (u_levels, u_tx_type) = planes.pop().expect("plane 1"); | ||
| 7034 | + // CfL averages the luma of the WHOLE pair, the region this one | ||
| 7035 | + // chroma transform covers. | ||
| 7036 | + let ac = alpha.map(|_| cfl_ac_q3_rect(y, ppx, ppy, pw, ph)); | ||
| 7037 | + for (plane, buf, levels, tx_type) in [ | ||
| 7038 | + (1usize, &mut *u, &u_levels, u_tx_type), | ||
| 7039 | + (2, &mut *v, &v_levels, v_tx_type), | ||
| 7040 | + ] { | ||
| 7041 | + let residual = dequant_and_inverse_typed_wh( | ||
| 7042 | + levels, | ||
| 7043 | + cw, | ||
| 7044 | + ch, | ||
| 7045 | + crate::decode::bit_depth(), | ||
| 7046 | + block_q_idx(), | ||
| 7047 | + plane_q_delta(plane).0, | ||
| 7048 | + plane_q_delta(plane).1, | ||
| 7049 | + tx_type, | ||
| 7050 | + ); | ||
| 7051 | + buf.reconstruct_rect( | ||
| 7052 | + cpx, | ||
| 7053 | + cpy, | ||
| 7054 | + cw, | ||
| 7055 | + ch, | ||
| 7056 | + uv_predict_mode, | ||
| 7057 | + angle_delta_uv, | ||
| 7058 | + pair_reach, | ||
| 7059 | + &residual, | ||
| 7060 | + alpha | ||
| 7061 | + .zip(ac.as_deref()) | ||
| 7062 | + .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), | ||
| 7063 | + None, | ||
| 7064 | + smooth_neighbor_uv, | ||
| 7065 | + ); | ||
| 7066 | + } | ||
| 7067 | + (u_levels, v_levels) | ||
| 7068 | + }; | ||
| 7069 | + neighbours.record_uv_mode_mi(pair_mi.0, pair_mi.1, pw / MI, ph / MI, uv_predict_mode); | ||
| 7070 | + // The chroma planes' coefficient context, over the PAIR's mi span | ||
| 7071 | + // (`decode_leaf_rect8`'s own rule: a subsampled plane's bound is | ||
| 7072 | + // the luma one rounded up to its 4x4 unit). | ||
| 7073 | + let u_state = neighbour_state(&u_levels); | ||
| 7074 | + let v_state = neighbour_state(&v_levels); | ||
| 7075 | + let round_up_even = |n: usize| n.div_ceil(2) * 2; | ||
| 7076 | + let bound_h = round_up_even(neighbours.mi_rows); | ||
| 7077 | + let bound_w = round_up_even(neighbours.mi_cols); | ||
| 7078 | + for cell in 0..(ph / MI) { | ||
| 7079 | + if pair_mi.0 + cell < bound_h | ||
| 7080 | + && let Some(slot) = neighbours.left.get_mut(pair_mi.0 + cell) | ||
| 7081 | + { | ||
| 7082 | + slot[1] = u_state; | ||
| 7083 | + slot[2] = v_state; | ||
| 7084 | + } | ||
| 7085 | + } | ||
| 7086 | + for cell in 0..(pw / MI) { | ||
| 7087 | + if pair_mi.1 + cell < bound_w | ||
| 7088 | + && let Some(slot) = neighbours.above.get_mut(pair_mi.1 + cell) | ||
| 7089 | + { | ||
| 7090 | + slot[1] = u_state; | ||
| 7091 | + slot[2] = v_state; | ||
| 7092 | + } | ||
| 7093 | + } | ||
| 7094 | + last_uv_mode = uv_predict_mode; | ||
| 7095 | + } | ||
| 7096 | + if horz { | ||
| 7097 | + RECT4_16_HORZ_HITS.with(|h| h.set(h.get() + 1)); | ||
| 7098 | + } else { | ||
| 7099 | + RECT4_16_VERT_HITS.with(|h| h.set(h.get() + 1)); | ||
| 7100 | + } | ||
| 7101 | + last_mode = mode; | ||
| 7102 | + prev = Some((lmi, mode)); | ||
| 7103 | + } | ||
| 7104 | + // The coarse 16-px cell holds one entry for the whole 16x16: the last | ||
| 7105 | + // strip is what a block below (right) sees through it, the mi-exact maps | ||
| 7106 | + // above answering everything finer. | ||
| 7107 | + neighbours.above_mode[c] = last_mode; | ||
| 7108 | + neighbours.left_mode[r] = last_mode; | ||
| 7109 | + neighbours.above_uv_mode[c] = last_uv_mode; | ||
| 7110 | + neighbours.left_uv_mode[r] = last_uv_mode; | ||
| 7111 | + neighbours.above_side[c] = bw; | ||
| 7112 | + neighbours.left_side[r] = bh; | ||
| 7113 | + Ok(()) | ||
| 7114 | +} | ||
| 7115 | + | ||
| 6744 | /// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/ | 7116 | /// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/ |
| 6745 | /// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` / | 7117 | /// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` / |
| 6746 | /// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike | 7118 | /// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike |
| @@ -6794,6 +7166,7 @@ fn decode_block_rect64( | |||
| 6794 | // the real 13-symbol `uv_mode_no_cfl` one and desynced the tile | 7166 | // the real 13-symbol `uv_mode_no_cfl` one and desynced the tile |
| 6795 | // from this block's very first symbol (lane-sbpart r3 bisect). | 7167 | // from this block's very first symbol (lane-sbpart r3 bisect). |
| 6796 | false, | 7168 | false, |
| 7169 | + true, | ||
| 6797 | bw, | 7170 | bw, |
| 6798 | bh, | 7171 | bh, |
| 6799 | enable_filter_intra, | 7172 | enable_filter_intra, |
| @@ -11705,9 +12078,29 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 11705 | neighbours.left_mode[sr] = mode_right; | 12078 | neighbours.left_mode[sr] = mode_right; |
| 11706 | continue; | 12079 | continue; |
| 11707 | } | 12080 | } |
| 12081 | + if part16 == PARTITION_HORZ_4 | ||
| 12082 | + || part16 == PARTITION_VERT_4 | ||
| 12083 | + { | ||
| 12084 | + decode_rect4_16( | ||
| 12085 | + &mut dec, | ||
| 12086 | + &mut cdfs, | ||
| 12087 | + &mut neighbours, | ||
| 12088 | + at16, | ||
| 12089 | + part16 == PARTITION_HORZ_4, | ||
| 12090 | + &mut y, | ||
| 12091 | + &mut u, | ||
| 12092 | + &mut v, | ||
| 12093 | + enable_filter_intra, | ||
| 12094 | + allow_screen_content_tools, | ||
| 12095 | + base_q_idx, | ||
| 12096 | + tx_select, | ||
| 12097 | + reduced_tx_set, | ||
| 12098 | + )?; | ||
| 12099 | + continue; | ||
| 12100 | + } | ||
| 11708 | if part16 != PARTITION_SPLIT { | 12101 | if part16 != PARTITION_SPLIT { |
| 11709 | return Err(unsupported( | 12102 | return Err(unsupported( |
| 11710 | - "a 1:4 partition below 16x16 (PARTITION_HORZ_4/VERT_4, four 16x4/4x16 strips -- this decoder codes NONE, HORZ, VERT, the four AB arms and a clean split at 16x16)", | 12103 | + "a 16x16-level partition value outside PARTITION_NONE..PARTITION_VERT_4", |
| 11711 | )); | 12104 | )); |
| 11712 | } | 12105 | } |
| 11713 | // A real (non-straddle) SPLIT of a | 12106 | // A real (non-straddle) SPLIT of a |
| @@ -19852,8 +20245,6 @@ mod tests { | |||
| 19852 | // string that blocks the shape otherwise. Either way the row is | 20245 | // string that blocks the shape otherwise. Either way the row is |
| 19853 | // pinned HERE, so the round that lifts one of those refusals cannot | 20246 | // pinned HERE, so the round that lifts one of those refusals cannot |
| 19854 | // land a wrong CDF row for the shape it unlocks. | 20247 | // land a wrong CDF row for the shape it unlocks. |
| 19855 | - const PART16: &str = "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes \ | ||
| 19856 | - only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)"; | ||
| 19857 | let libaom: &[(usize, usize, u16, Option<&str>)] = &[ | 20248 | let libaom: &[(usize, usize, u16, Option<&str>)] = &[ |
| 19858 | (4, 4, 4621, None), | 20249 | (4, 4, 4621, None), |
| 19859 | (4, 8, 6743, None), | 20250 | (4, 8, 6743, None), |
| @@ -19868,8 +20259,10 @@ mod tests { | |||
| 19868 | // The 1:4 strips: a 16x16-level PARTITION_HORZ_4/VERT_4 gives | 20259 | // The 1:4 strips: a 16x16-level PARTITION_HORZ_4/VERT_4 gives |
| 19869 | // 4x16/16x4 (still refused by name before any leaf is coded), | 20260 | // 4x16/16x4 (still refused by name before any leaf is coded), |
| 19870 | // a 32x32-level one 8x32/32x8. | 20261 | // a 32x32-level one 8x32/32x8. |
| 19871 | - (4, 16, 12770, Some(PART16)), | 20262 | + // lane-r14: the 16-level pair is coded now (`decode_rect4_16`), |
| 19872 | - (16, 4, 10368, Some(PART16)), | 20263 | + // owning classes 13/12. |
| 20264 | + (4, 16, 12770, None), | ||
| 20265 | + (16, 4, 10368, None), | ||
| 19873 | // lane-fi32x8 r1: the 32-level pair is coded (four 32x8/8x32 | 20266 | // lane-fi32x8 r1: the 32-level pair is coded (four 32x8/8x32 |
| 19874 | // strips per `PARTITION_HORZ_4`/`VERT_4`) and now owns classes | 20267 | // strips per `PARTITION_HORZ_4`/`VERT_4`) and now owns classes |
| 19875 | // 10/11; only the 16-level pair is still refused before any leaf. | 20268 | // 10/11; only the 16-level pair is still refused before any leaf. |
crates/ec-av1/src/refusal_inventory.rsmodified+2 -1
| @@ -34,7 +34,8 @@ const REFUSALS: &[&str] = &[ | |||
| 34 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", | 34 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", |
| 35 | "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", | 35 | "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", |
| 36 | "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", | 36 | "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", |
| 37 | - "a 1:4 partition below 16x16 (PARTITION_HORZ_4/VERT_4, four 16x4/4x16 strips -- this decoder codes NONE, HORZ, VERT, the four AB arms and a clean split at 16x16)", | 37 | + "a 16x16-level partition value outside PARTITION_NONE..PARTITION_VERT_4", |
| 38 | + "a 16x4/4x16 strip whose transform is split (sub_tx_size_map[TX_16X4] == TX_8X4; the per-unit walk is not ported at this shape)", | ||
| 38 | "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", | 39 | "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", |
| 39 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", | 40 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| 40 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", | 41 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
crates/ec-av1/src/stream.rsmodified+222 -0
| @@ -18180,6 +18180,228 @@ mod tests { | |||
| 18180 | /// then compared pixel-exact are counted (class | 18180 | /// then compared pixel-exact are counted (class |
| 18181 | /// gate-skips-on-its-own-failure); the 10-bit arm is what retires | 18181 | /// gate-skips-on-its-own-failure); the 10-bit arm is what retires |
| 18182 | /// `enable-1to4-partitions` from `NEVER_EXERCISED_10BIT`. | 18182 | /// `enable-1to4-partitions` from `NEVER_EXERCISED_10BIT`. |
| 18183 | + /// lane-r14: the 16x16-level 1:4 pair -- four 16x4 (`PARTITION_HORZ_4`) or | ||
| 18184 | + /// 4x16 (`PARTITION_VERT_4`) strips, the shape the wall | ||
| 18185 | + /// "a 1:4 partition below 16x16" refused. Fixture: 4-PIXEL bands (the | ||
| 18186 | + /// 8-pixel ones of the 32-level gate above, one size down -- a 16x4 strip | ||
| 18187 | + /// is flat where a 16x8 one is not), transposed per attempt so a | ||
| 18188 | + /// transposed scan or nz-map table cannot pass (class | ||
| 18189 | + /// scan-weights-cross-axis), plus an explicit-seed noise layer that keeps | ||
| 18190 | + /// aomenc out of screen-content mode. `--enable-filter-intra=1` and | ||
| 18191 | + /// `--enable-cfl-intra=1` are ON: this shape reads `use_filter_intra` off | ||
| 18192 | + /// its own CDF rows (classes 12/13) and its CfL averages the whole 16x8 | ||
| 18193 | + /// (8x16) luma PAIR, not the strip. `--enable-tx-size-search=0`: a split | ||
| 18194 | + /// transform at this shape is still refused by name. | ||
| 18195 | + /// | ||
| 18196 | + /// Counters: 16x4 strips, 4x16 strips, chroma-reference strips (the odd | ||
| 18197 | + /// strip of each 4:2:0 pair, the only one that codes chroma) and strips | ||
| 18198 | + /// with a coded residual must all be nonzero over the compared attempts, | ||
| 18199 | + /// and only attempts that DECODED and were compared pixel-exact count | ||
| 18200 | + /// (class gate-skips-on-its-own-failure). | ||
| 18201 | + #[test] | ||
| 18202 | + fn a_real_aomenc_stream_with_a_16_level_1to4_partition_decodes_pixel_exact() { | ||
| 18203 | + const NAME: &str = | ||
| 18204 | + "a_real_aomenc_stream_with_a_16_level_1to4_partition_decodes_pixel_exact"; | ||
| 18205 | + let _gate_lock = lock_gate_counters(); | ||
| 18206 | + if !have_ffmpeg() { | ||
| 18207 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 18208 | + return; | ||
| 18209 | + } | ||
| 18210 | + if !have_aomenc() { | ||
| 18211 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 18212 | + return; | ||
| 18213 | + } | ||
| 18214 | + let (width, height, frame_count) = (192usize, 128usize, 1usize); | ||
| 18215 | + let n_attempts: u32 = std::env::var("EC_R14_GATE_ATTEMPTS") | ||
| 18216 | + .ok() | ||
| 18217 | + .and_then(|s| s.parse().ok()) | ||
| 18218 | + .unwrap_or(8); | ||
| 18219 | + for bit_depth in [8u32, 10u32] { | ||
| 18220 | + let mut named_refusals = 0u32; | ||
| 18221 | + let mut matched = 0u32; | ||
| 18222 | + let (mut horz_proved, mut vert_proved) = (0usize, 0usize); | ||
| 18223 | + let (mut chroma_proved, mut coeff_proved) = (0usize, 0usize); | ||
| 18224 | + let (mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32); | ||
| 18225 | + for attempt in 0..n_attempts { | ||
| 18226 | + let seed = 42 + attempt; | ||
| 18227 | + let duration = frame_count as f64 / 25.0; | ||
| 18228 | + let axis = if attempt % 2 == 0 { "Y" } else { "X" }; | ||
| 18229 | + let step = 67 + (attempt / 2) * 12; | ||
| 18230 | + let noise = 6 + (attempt % 4) * 3; | ||
| 18231 | + let source = format!( | ||
| 18232 | + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ | ||
| 18233 | + geq=lum='mod(floor({axis}/4)*{step},256)',\ | ||
| 18234 | + noise=alls={noise}:all_seed={seed},format=yuv420p" | ||
| 18235 | + ); | ||
| 18236 | + let cq_level = format!("--cq-level={}", 24 + (attempt % 4) * 8); | ||
| 18237 | + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 18238 | + let y4m = Command::new("ffmpeg") | ||
| 18239 | + .args([ | ||
| 18240 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), | ||
| 18241 | + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | ||
| 18242 | + ]) | ||
| 18243 | + .stdin(Stdio::null()) | ||
| 18244 | + .stdout(Stdio::piped()) | ||
| 18245 | + .stderr(Stdio::piped()) | ||
| 18246 | + .output() | ||
| 18247 | + .expect("ffmpeg failed to run"); | ||
| 18248 | + assert!( | ||
| 18249 | + y4m.status.success(), | ||
| 18250 | + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", | ||
| 18251 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 18252 | + ); | ||
| 18253 | + let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 18254 | + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 18255 | + let args: Vec<&str> = vec![ | ||
| 18256 | + "--codec=av1", | ||
| 18257 | + "--passes=1", | ||
| 18258 | + "--end-usage=q", | ||
| 18259 | + &cq_level, | ||
| 18260 | + "--cpu-used=0", | ||
| 18261 | + "--threads=1", | ||
| 18262 | + "--row-mt=0", | ||
| 18263 | + "--sb-size=64", | ||
| 18264 | + &depth_arg, | ||
| 18265 | + &input_depth_arg, | ||
| 18266 | + "--enable-rect-partitions=1", | ||
| 18267 | + "--enable-ab-partitions=0", | ||
| 18268 | + "--enable-1to4-partitions=1", | ||
| 18269 | + "--min-partition-size=4", | ||
| 18270 | + "--max-partition-size=16", | ||
| 18271 | + "--enable-restoration=0", | ||
| 18272 | + "--enable-palette=0", | ||
| 18273 | + "--deltaq-mode=0", | ||
| 18274 | + "--enable-filter-intra=1", | ||
| 18275 | + "--enable-cfl-intra=1", | ||
| 18276 | + "--enable-intrabc=0", | ||
| 18277 | + "--enable-tx-size-search=0", | ||
| 18278 | + "--obu", | ||
| 18279 | + "-o", | ||
| 18280 | + "-", | ||
| 18281 | + "-", | ||
| 18282 | + ]; | ||
| 18283 | + let mut child = Command::new(aomenc_path()) | ||
| 18284 | + .args(&args) | ||
| 18285 | + .stdin(Stdio::piped()) | ||
| 18286 | + .stdout(Stdio::piped()) | ||
| 18287 | + .stderr(Stdio::piped()) | ||
| 18288 | + .spawn() | ||
| 18289 | + .expect("aomenc failed to start"); | ||
| 18290 | + child | ||
| 18291 | + .stdin | ||
| 18292 | + .take() | ||
| 18293 | + .expect("aomenc stdin") | ||
| 18294 | + .write_all(&y4m.stdout) | ||
| 18295 | + .expect("writing y4m to aomenc"); | ||
| 18296 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 18297 | + assert!( | ||
| 18298 | + out.status.success(), | ||
| 18299 | + "aomenc refused the fixture: {}", | ||
| 18300 | + String::from_utf8_lossy(&out.stderr) | ||
| 18301 | + ); | ||
| 18302 | + let stream = out.stdout; | ||
| 18303 | + let before = crate::decode::rect4_16_counters(); | ||
| 18304 | + let frames = match decode_stream(&stream) { | ||
| 18305 | + Err(e) => { | ||
| 18306 | + let msg = e.to_string(); | ||
| 18307 | + assert!( | ||
| 18308 | + msg.contains("unsupported"), | ||
| 18309 | + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, seed \ | ||
| 18310 | + {seed}): {msg}" | ||
| 18311 | + ); | ||
| 18312 | + named_refusals += 1; | ||
| 18313 | + eprintln!("{bit_depth}-bit seed {seed} refusal: {msg}"); | ||
| 18314 | + continue; | ||
| 18315 | + } | ||
| 18316 | + Ok(frames) => frames, | ||
| 18317 | + }; | ||
| 18318 | + let now = crate::decode::rect4_16_counters(); | ||
| 18319 | + let (horz, vert, chroma, coeff) = ( | ||
| 18320 | + now.0 - before.0, | ||
| 18321 | + now.1 - before.1, | ||
| 18322 | + now.2 - before.2, | ||
| 18323 | + now.3 - before.3, | ||
| 18324 | + ); | ||
| 18325 | + let ffmpeg_frames = if bit_depth == 10 { | ||
| 18326 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 18327 | + } else { | ||
| 18328 | + ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 18329 | + }; | ||
| 18330 | + assert_eq!(frames.len(), frame_count); | ||
| 18331 | + let mismatched = frames | ||
| 18332 | + .iter() | ||
| 18333 | + .zip(&ffmpeg_frames) | ||
| 18334 | + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | ||
| 18335 | + if horz + vert == 0 { | ||
| 18336 | + out_of_scope += 1; | ||
| 18337 | + if mismatched { | ||
| 18338 | + out_of_scope_mismatch += 1; | ||
| 18339 | + eprintln!( | ||
| 18340 | + "{NAME}: {bit_depth}-bit seed {seed} MISMATCHES with zero 16-level \ | ||
| 18341 | + 1:4 strips -- a pre-existing defect of another shape" | ||
| 18342 | + ); | ||
| 18343 | + } | ||
| 18344 | + continue; | ||
| 18345 | + } | ||
| 18346 | + if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { | ||
| 18347 | + std::fs::write(&path, &stream).expect("writing pinned stream"); | ||
| 18348 | + eprintln!( | ||
| 18349 | + "EC_AV1_GATE_DUMP: wrote mismatching stream ({bit_depth}-bit, seed \ | ||
| 18350 | + {seed}) to {path}" | ||
| 18351 | + ); | ||
| 18352 | + } | ||
| 18353 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 18354 | + assert_eq!( | ||
| 18355 | + got.y, want.y, | ||
| 18356 | + "{NAME} frame {i} luma vs ffmpeg ({bit_depth}-bit, seed {seed})" | ||
| 18357 | + ); | ||
| 18358 | + assert_eq!( | ||
| 18359 | + got.u, want.u, | ||
| 18360 | + "{NAME} frame {i} U vs ffmpeg ({bit_depth}-bit, seed {seed})" | ||
| 18361 | + ); | ||
| 18362 | + assert_eq!( | ||
| 18363 | + got.v, want.v, | ||
| 18364 | + "{NAME} frame {i} V vs ffmpeg ({bit_depth}-bit, seed {seed})" | ||
| 18365 | + ); | ||
| 18366 | + } | ||
| 18367 | + horz_proved += horz; | ||
| 18368 | + vert_proved += vert; | ||
| 18369 | + chroma_proved += chroma; | ||
| 18370 | + coeff_proved += coeff; | ||
| 18371 | + matched += 1; | ||
| 18372 | + } | ||
| 18373 | + assert!( | ||
| 18374 | + matched > 0, | ||
| 18375 | + "{NAME}: every {bit_depth}-bit attempt refused or fell out of scope ({named_refusals} \ | ||
| 18376 | + refusals, {out_of_scope} out of scope); the gate proved nothing" | ||
| 18377 | + ); | ||
| 18378 | + assert_eq!( | ||
| 18379 | + out_of_scope_mismatch, 0, | ||
| 18380 | + "{NAME}: {out_of_scope_mismatch} {bit_depth}-bit attempt(s) mismatch with no \ | ||
| 18381 | + 16-level 1:4 strip at all" | ||
| 18382 | + ); | ||
| 18383 | + assert!( | ||
| 18384 | + horz_proved > 0 && vert_proved > 0, | ||
| 18385 | + "{NAME}: {bit_depth}-bit compared attempts decoded {horz_proved} 16x4 and \ | ||
| 18386 | + {vert_proved} 4x16 strips -- both orientations must fire or a transposed table \ | ||
| 18387 | + passes" | ||
| 18388 | + ); | ||
| 18389 | + assert!( | ||
| 18390 | + chroma_proved > 0, | ||
| 18391 | + "{NAME}: {bit_depth}-bit compared attempts closed {chroma_proved} chroma pairs" | ||
| 18392 | + ); | ||
| 18393 | + assert!( | ||
| 18394 | + coeff_proved > 0, | ||
| 18395 | + "{NAME}: {bit_depth}-bit compared attempts coded no residual on any strip" | ||
| 18396 | + ); | ||
| 18397 | + eprintln!( | ||
| 18398 | + "{NAME}: {bit_depth}-bit {matched} compared attempts, {horz_proved} 16x4 / \ | ||
| 18399 | + {vert_proved} 4x16 strips, {chroma_proved} chroma pairs, {coeff_proved} coded \ | ||
| 18400 | + strips, {named_refusals} refusals, {out_of_scope} out of scope" | ||
| 18401 | + ); | ||
| 18402 | + } | ||
| 18403 | + } | ||
| 18404 | + | ||
| 18183 | #[test] | 18405 | #[test] |
| 18184 | // lane-tx64x16 r4: the fixture r3 could not find. `gradients` never wins | 18406 | // lane-tx64x16 r4: the fixture r3 could not find. `gradients` never wins |
| 18185 | // a 32-level 1:4 shape; 8-pixel BANDS do -- each 32x8 strip is flat, so | 18407 | // a 32-level 1:4 shape; 8-pixel BANDS do -- each 32x8 strip is flat, so |