Merge branch 'lane-r14' (a2e2e29): 16x16-level 1:4 partitions decode -- FILTER_INTRA rows 12/13 (BLOCK_16X4/4X16) and the rect base-context offsets
Browse files at this commit7 changed files +1155 -24
- crates/ec-av1/src/cdf.rs +7 -1
- crates/ec-av1/src/cdf_state.rs +41 -1
- crates/ec-av1/src/decode.rs +611 -21
- crates/ec-av1/src/refusal_inventory.rs +4 -1
- crates/ec-av1/src/stream.rs +276 -0
- lanes/r14-r1.report.md +119 -0
- lanes/r14-r2.report.md +97 -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
| @@ -214,6 +214,22 @@ pub(crate) enum TxbSet { | |||
| 214 | /// `tx_size_sqr == TX_4X4`, intra returns `EXT_TX_SET_DTT4_IDTX_1DDCT`, | 214 | /// `tx_size_sqr == TX_4X4`, intra returns `EXT_TX_SET_DTT4_IDTX_1DDCT`, |
| 215 | /// the same seven-symbol set (and same `TX_4X4` row) `Luma4Set1` reads. | 215 | /// the same seven-symbol set (and same `TX_4X4` row) `Luma4Set1` reads. |
| 216 | LumaRect4x8Set1, | 216 | LumaRect4x8Set1, |
| 217 | + /// The luma 16x4/4x16 transform of a 16x16-level `PARTITION_HORZ_4`/ | ||
| 218 | + /// `PARTITION_VERT_4` strip (lane-r14). `get_txsize_entropy_ctx` | ||
| 219 | + /// ((`txsize_sqr_map` + `txsize_sqr_up_map` + 1) >> 1) resolves `TX_16X4` | ||
| 220 | + /// to `TX_8X8`, and the transform has 64 coded positions, so EVERY table | ||
| 221 | + /// here is [`Luma8`](TxbSet::Luma8)'s (`eob_pt_64` included) except | ||
| 222 | + /// `tx_type`: `read_tx_type` indexes `intra_ext_tx_cdf[eset] | ||
| 223 | + /// [txsize_sqr_map[TX_16X4]]` = the `TX_4X4` row, and | ||
| 224 | + /// `av1_get_ext_tx_set_type` at `tx_size_sqr_up == TX_16X16` with | ||
| 225 | + /// `tx_size_sqr == TX_4X4` returns `EXT_TX_SET_DTT4_IDTX` under | ||
| 226 | + /// `reduced_tx_set` -- the same pair [`LumaRect4x8`](TxbSet::LumaRect4x8) | ||
| 227 | + /// reads, which differs from this variant only in its 32-position `eob_pt`. | ||
| 228 | + LumaRect16x4, | ||
| 229 | + /// [`LumaRect16x4`](TxbSet::LumaRect16x4)'s `reduced_tx_set: false` | ||
| 230 | + /// counterpart: `EXT_TX_SET_DTT4_IDTX_1DDCT`, the seven-symbol `TX_4X4` | ||
| 231 | + /// row [`LumaRect4x8Set1`](TxbSet::LumaRect4x8Set1) reads. | ||
| 232 | + LumaRect16x4Set1, | ||
| 217 | } | 233 | } |
| 218 | 234 | ||
| 219 | /// The tables one transform block is coded with, borrowed from the state for | 235 | /// The tables one transform block is coded with, borrowed from the state for |
| @@ -569,7 +585,7 @@ pub(crate) struct Cdfs { | |||
| 569 | /// `[1]`=8x8, `[2]`=16x16, `[3]`=32x32, `[4]`=32x16, `[5]`=16x32, | 585 | /// `[1]`=8x8, `[2]`=16x16, `[3]`=32x32, `[4]`=32x16, `[5]`=16x32, |
| 570 | /// `[6]`=16x8, `[7]`=8x16, `[8]`=4x8, `[9]`=8x4, `[10]`=32x8, `[11]`=8x32) -- | 586 | /// `[6]`=16x8, `[7]`=8x16, `[8]`=4x8, `[9]`=8x4, `[10]`=32x8, `[11]`=8x32) -- |
| 571 | /// see [`cdf::FILTER_INTRA`]. | 587 | /// see [`cdf::FILTER_INTRA`]. |
| 572 | - pub filter_intra: [[u16; 3]; 12], | 588 | + pub filter_intra: [[u16; 3]; 14], |
| 573 | /// Which `FILTER_INTRA_MODES` entry a `use_filter_intra` block picks. | 589 | /// Which `FILTER_INTRA_MODES` entry a `use_filter_intra` block picks. |
| 574 | pub filter_intra_mode: [u16; 6], | 590 | pub filter_intra_mode: [u16; 6], |
| 575 | /// `TxMode::Select`'s `tx_depth` flag at an 8x8 block, by `tx_size_context` | 591 | /// `TxMode::Select`'s `tx_depth` flag at an 8x8 block, by `tx_size_context` |
| @@ -1807,6 +1823,30 @@ impl Cdfs { | |||
| 1807 | tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()), | 1823 | tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()), |
| 1808 | eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1), | 1824 | eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1), |
| 1809 | }, | 1825 | }, |
| 1826 | + TxbSet::LumaRect16x4 => TxbTables { | ||
| 1827 | + side: 8, | ||
| 1828 | + txb_skip: &mut self.txb_skip_luma_8, | ||
| 1829 | + eob_pt: &mut self.eob_pt_64_luma, | ||
| 1830 | + eob_extra: &mut self.eob_extra_luma_8, | ||
| 1831 | + base: &mut self.base_luma_8, | ||
| 1832 | + base_eob: &mut self.base_eob_luma_8, | ||
| 1833 | + br: &mut self.br_luma_8, | ||
| 1834 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1835 | + tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()), | ||
| 1836 | + eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), | ||
| 1837 | + }, | ||
| 1838 | + TxbSet::LumaRect16x4Set1 => TxbTables { | ||
| 1839 | + side: 8, | ||
| 1840 | + txb_skip: &mut self.txb_skip_luma_8, | ||
| 1841 | + eob_pt: &mut self.eob_pt_64_luma, | ||
| 1842 | + eob_extra: &mut self.eob_extra_luma_8, | ||
| 1843 | + base: &mut self.base_luma_8, | ||
| 1844 | + base_eob: &mut self.base_eob_luma_8, | ||
| 1845 | + br: &mut self.br_luma_8, | ||
| 1846 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1847 | + tx_type: Some(self.intra_tx_type_4_set1[mode].as_mut_slice()), | ||
| 1848 | + eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), | ||
| 1849 | + }, | ||
| 1810 | TxbSet::LumaRect16x8Inter => TxbTables { | 1850 | TxbSet::LumaRect16x8Inter => TxbTables { |
| 1811 | side: 16, | 1851 | side: 16, |
| 1812 | txb_skip: &mut self.txb_skip_luma_16, | 1852 | txb_skip: &mut self.txb_skip_luma_16, |
crates/ec-av1/src/decode.rsmodified+611 -21
| @@ -916,6 +916,10 @@ thread_local! { | |||
| 916 | // their rect max transform into square sub-transforms. | 916 | // their rect max transform into square sub-transforms. |
| 917 | static RECT_INTER_TU_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | 917 | static RECT_INTER_TU_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 918 | static RECT_INTER_TXSPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | 918 | static RECT_INTER_TXSPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 919 | + // lane-r14 r2: luma transform units of an inter strip with a 64-px axis | ||
| 920 | + // (64x32/32x64/64x16/16x64), whose coefficients are coded as the | ||
| 921 | + // truncated low-32 corner. | ||
| 922 | + static RECT64_INTER_TU_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 919 | // lane-inter4 r3: 16x16-level PARTITION_HORZ / PARTITION_VERT on an inter | 923 | // lane-inter4 r3: 16x16-level PARTITION_HORZ / PARTITION_VERT on an inter |
| 920 | // frame -- 16x8 and 8x16 inter leaves. | 924 | // frame -- 16x8 and 8x16 inter leaves. |
| 921 | static INTER_LEAF16_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | 925 | static INTER_LEAF16_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| @@ -963,6 +967,11 @@ pub(crate) fn rect_inter_txsplit_hits() -> usize { | |||
| 963 | RECT_INTER_TXSPLIT_HITS.with(|c| c.get()) | 967 | RECT_INTER_TXSPLIT_HITS.with(|c| c.get()) |
| 964 | } | 968 | } |
| 965 | 969 | ||
| 970 | +/// Current value of [`RECT64_INTER_TU_HITS`] (lane-r14 r2). | ||
| 971 | +pub(crate) fn rect64_inter_tu_hits() -> usize { | ||
| 972 | + RECT64_INTER_TU_HITS.with(|c| c.get()) | ||
| 973 | +} | ||
| 974 | + | ||
| 966 | /// Sets the current thread's [`TX_SELECT_INTER`]/[`REDUCED_TX_SET_INTER`]/ | 975 | /// Sets the current thread's [`TX_SELECT_INTER`]/[`REDUCED_TX_SET_INTER`]/ |
| 967 | /// [`ENABLE_FILTER_INTRA_INTER`]. | 976 | /// [`ENABLE_FILTER_INTRA_INTER`]. |
| 968 | pub(crate) fn set_inter_tx_mode( | 977 | pub(crate) fn set_inter_tx_mode( |
| @@ -2102,6 +2111,30 @@ pub(crate) fn rect4_coeff_hits() -> usize { | |||
| 2102 | RECT4_COEFF_HITS.with(|c| c.get()) | 2111 | RECT4_COEFF_HITS.with(|c| c.get()) |
| 2103 | } | 2112 | } |
| 2104 | 2113 | ||
| 2114 | +// lane-r14: the 16x16-level 1:4 pair -- four 16x4 (`PARTITION_HORZ_4`) or | ||
| 2115 | +// 4x16 (`PARTITION_VERT_4`) strips, `CHROMA` counting the odd strips that | ||
| 2116 | +// close a 4:2:0 chroma pair and `COEFF` the strips with a coded residual. | ||
| 2117 | +thread_local! { | ||
| 2118 | + static RECT4_16_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2119 | + static RECT4_16_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2120 | + static RECT4_16_CHROMA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2121 | + static RECT4_16_COEFF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2122 | + static RECT4_16_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2123 | +} | ||
| 2124 | + | ||
| 2125 | +/// Current values of the 16x16-level 1:4 counters: `(16x4 strips, 4x16 | ||
| 2126 | +/// strips, chroma-reference strips, strips with a coded residual, strips | ||
| 2127 | +/// whose luma transform is split)`. | ||
| 2128 | +pub fn rect4_16_counters() -> (usize, usize, usize, usize, usize) { | ||
| 2129 | + ( | ||
| 2130 | + RECT4_16_HORZ_HITS.with(|c| c.get()), | ||
| 2131 | + RECT4_16_VERT_HITS.with(|c| c.get()), | ||
| 2132 | + RECT4_16_CHROMA_HITS.with(|c| c.get()), | ||
| 2133 | + RECT4_16_COEFF_HITS.with(|c| c.get()), | ||
| 2134 | + RECT4_16_SPLIT_HITS.with(|c| c.get()), | ||
| 2135 | + ) | ||
| 2136 | +} | ||
| 2137 | + | ||
| 2105 | /// Current value of `RECT4_32_HORZ_HITS` (32x8 strips decoded). | 2138 | /// Current value of `RECT4_32_HORZ_HITS` (32x8 strips decoded). |
| 2106 | pub(crate) fn rect4_32_horz_hits() -> usize { | 2139 | pub(crate) fn rect4_32_horz_hits() -> usize { |
| 2107 | RECT4_32_HORZ_HITS.with(|c| c.get()) | 2140 | RECT4_32_HORZ_HITS.with(|c| c.get()) |
| @@ -4930,6 +4963,10 @@ fn filter_intra_size_class_rect(bw: usize, bh: usize) -> Option<usize> { | |||
| 4930 | // tile (class symbol-consumption-gap). | 4963 | // tile (class symbol-consumption-gap). |
| 4931 | (32, 8) => Some(10), | 4964 | (32, 8) => Some(10), |
| 4932 | (8, 32) => Some(11), | 4965 | (8, 32) => Some(11), |
| 4966 | + // lane-r14: the 16x16-level 1:4 pair (`decode_rect4_16`'s 16x4/4x16 | ||
| 4967 | + // strips), rows 17/16 of `default_filter_intra_cdfs`. | ||
| 4968 | + (16, 4) => Some(12), | ||
| 4969 | + (4, 16) => Some(13), | ||
| 4933 | _ if bw == bh => filter_intra_size_class(bw), | 4970 | _ if bw == bh => filter_intra_size_class(bw), |
| 4934 | _ => None, | 4971 | _ => None, |
| 4935 | } | 4972 | } |
| @@ -4955,7 +4992,13 @@ fn palette_bsize_ctx(side: usize) -> Option<usize> { | |||
| 4955 | /// `trailing_zeros` is `log2` exactly. `None` past `av1_allow_palette`'s own | 4992 | /// `trailing_zeros` is `log2` exactly. `None` past `av1_allow_palette`'s own |
| 4956 | /// bound (`block_size_wide/high <= 64`, `sb_type >= BLOCK_8X8`). | 4993 | /// bound (`block_size_wide/high <= 64`, `sb_type >= BLOCK_8X8`). |
| 4957 | fn palette_bsize_ctx_wh(bw: usize, bh: usize) -> Option<usize> { | 4994 | fn palette_bsize_ctx_wh(bw: usize, bh: usize) -> Option<usize> { |
| 4958 | - if !(8..=64).contains(&bw) || !(8..=64).contains(&bh) { | 4995 | + // lane-r14: `av1_allow_palette`'s bound is `sb_type >= BLOCK_8X8` by the |
| 4996 | + // BLOCK_SIZES_ALL enum INDEX, which the 1:4 shapes BLOCK_4X16 (16) and | ||
| 4997 | + // BLOCK_16X4 (17) clear -- a 64-pixel block, so `av1_get_palette_bsize_ctx` | ||
| 4998 | + // (`num_pels_log2 - num_pels_log2[BLOCK_8X8]`) is 0 for them, exactly as | ||
| 4999 | + // for an 8x8. Reading the dimension bound as "both sides >= 8" dropped | ||
| 5000 | + // `palette_y_mode` on every 16x4/4x16 strip of a screen-content frame. | ||
| 5001 | + if bw > 64 || bh > 64 || bw * bh < 64 { | ||
| 4959 | return None; | 5002 | return None; |
| 4960 | } | 5003 | } |
| 4961 | Some(((bw * bh) as u32).trailing_zeros() as usize - 6) | 5004 | Some(((bw * bh) as u32).trailing_zeros() as usize - 6) |
| @@ -5277,6 +5320,12 @@ fn read_intra_mode_rect( | |||
| 5277 | above_mode: usize, | 5320 | above_mode: usize, |
| 5278 | left_mode: usize, | 5321 | left_mode: usize, |
| 5279 | cfl: bool, | 5322 | cfl: bool, |
| 5323 | + // lane-r14: `is_chroma_reference` -- false only for a strip one mi tall | ||
| 5324 | + // (or wide) that is NOT the odd one of its 4:2:0 pair, where libaom reads | ||
| 5325 | + // no `uv_mode`/`cfl_alpha`/`angle_delta_uv`/`palette_uv` at all (the pair's | ||
| 5326 | + // chroma is coded once, on the closing strip). Every other caller is a | ||
| 5327 | + // block big enough to own its chroma and passes `true`. | ||
| 5328 | + has_chroma: bool, | ||
| 5280 | bw: usize, | 5329 | bw: usize, |
| 5281 | bh: usize, | 5330 | bh: usize, |
| 5282 | enable_filter_intra: bool, | 5331 | enable_filter_intra: bool, |
| @@ -5340,21 +5389,23 @@ fn read_intra_mode_rect( | |||
| 5340 | 0 | 5389 | 0 |
| 5341 | }; | 5390 | }; |
| 5342 | istep!("angle_y", angle_delta_y); | 5391 | istep!("angle_y", angle_delta_y); |
| 5343 | - let uv_mode = if cfl { | 5392 | + let uv_mode = if !has_chroma { |
| 5393 | + DC_PRED | ||
| 5394 | + } else if cfl { | ||
| 5344 | dec.symbol(&mut cdfs.uv_mode_cfl[mode]) | 5395 | dec.symbol(&mut cdfs.uv_mode_cfl[mode]) |
| 5345 | } else { | 5396 | } else { |
| 5346 | dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) | 5397 | dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) |
| 5347 | }; | 5398 | }; |
| 5348 | istep!("uv_mode", uv_mode as i32); | 5399 | istep!("uv_mode", uv_mode as i32); |
| 5349 | - let alpha = if cfl && uv_mode == UV_CFL_PRED { | 5400 | + let alpha = if has_chroma && cfl && uv_mode == UV_CFL_PRED { |
| 5350 | Some(read_cfl_alphas(dec, cdfs)) | 5401 | Some(read_cfl_alphas(dec, cdfs)) |
| 5351 | } else { | 5402 | } else { |
| 5352 | None | 5403 | None |
| 5353 | }; | 5404 | }; |
| 5354 | - if (9..=12).contains(&uv_mode) { | 5405 | + if has_chroma && (9..=12).contains(&uv_mode) { |
| 5355 | SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1)); | 5406 | SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1)); |
| 5356 | } | 5407 | } |
| 5357 | - let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) { | 5408 | + let angle_delta_uv = if has_chroma && (V_PRED..=D67_PRED).contains(&uv_mode) { |
| 5358 | DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1)); | 5409 | DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1)); |
| 5359 | read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED]) | 5410 | read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED]) |
| 5360 | } else { | 5411 | } else { |
| @@ -5394,7 +5445,11 @@ fn read_intra_mode_rect( | |||
| 5394 | palette_y_pending = Some((n, colors)); | 5445 | palette_y_pending = Some((n, colors)); |
| 5395 | } | 5446 | } |
| 5396 | let palette_uv_mode_ctx = usize::from(use_palette_y); | 5447 | let palette_uv_mode_ctx = usize::from(use_palette_y); |
| 5397 | - if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[palette_uv_mode_ctx]) != 0 { | 5448 | + // `read_palette_mode_info`'s own `xd->is_chroma_ref` guard. |
| 5449 | + if has_chroma | ||
| 5450 | + && uv_mode == DC_PRED | ||
| 5451 | + && dec.symbol(&mut cdfs.palette_uv_mode[palette_uv_mode_ctx]) != 0 | ||
| 5452 | + { | ||
| 5398 | let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]); | 5453 | let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]); |
| 5399 | let (u_colors, v_colors) = read_palette_colors_uv(dec, n, palette_uv_cache); | 5454 | let (u_colors, v_colors) = read_palette_colors_uv(dec, n, palette_uv_cache); |
| 5400 | palette_uv_pending = Some((n, u_colors, v_colors)); | 5455 | palette_uv_pending = Some((n, u_colors, v_colors)); |
| @@ -6177,6 +6232,7 @@ fn decode_block_rect( | |||
| 6177 | nb_above_mode, | 6232 | nb_above_mode, |
| 6178 | nb_left_mode, | 6233 | nb_left_mode, |
| 6179 | true, | 6234 | true, |
| 6235 | + true, | ||
| 6180 | bw, | 6236 | bw, |
| 6181 | bh, | 6237 | bh, |
| 6182 | enable_filter_intra, | 6238 | enable_filter_intra, |
| @@ -6651,6 +6707,7 @@ fn decode_leaf_rect( | |||
| 6651 | above_mode, | 6707 | above_mode, |
| 6652 | left_mode, | 6708 | left_mode, |
| 6653 | true, | 6709 | true, |
| 6710 | + true, | ||
| 6654 | bw, | 6711 | bw, |
| 6655 | bh, | 6712 | bh, |
| 6656 | enable_filter_intra, | 6713 | enable_filter_intra, |
| @@ -6930,6 +6987,7 @@ fn decode_block_rect4( | |||
| 6930 | above_mode, | 6987 | above_mode, |
| 6931 | left_mode, | 6988 | left_mode, |
| 6932 | true, | 6989 | true, |
| 6990 | + true, | ||
| 6933 | bw, | 6991 | bw, |
| 6934 | bh, | 6992 | bh, |
| 6935 | enable_filter_intra, | 6993 | enable_filter_intra, |
| @@ -7231,6 +7289,434 @@ fn decode_block_rect4( | |||
| 7231 | Ok((mode, uv_predict_mode)) | 7289 | Ok((mode, uv_predict_mode)) |
| 7232 | } | 7290 | } |
| 7233 | 7291 | ||
| 7292 | +/// Decodes the four 16x4 / 4x16 strips of a 16x16-level `PARTITION_HORZ_4` / | ||
| 7293 | +/// `PARTITION_VERT_4` (lane-r14) -- [`decode_block_rect4`]'s pair one level | ||
| 7294 | +/// down, and the first shape here whose luma block is a single mi row (or | ||
| 7295 | +/// column). | ||
| 7296 | +/// | ||
| 7297 | +/// What is new at this size is CHROMA. `is_chroma_reference` | ||
| 7298 | +/// (`av1_common_int.h`) is false for a 4:2:0 block one mi tall (wide) on an | ||
| 7299 | +/// EVEN mi row (column), so strips 0 and 2 read no `uv_mode`/`cfl_alpha`/ | ||
| 7300 | +/// `angle_delta_uv` at all and code no chroma residual; strips 1 and 3 close | ||
| 7301 | +/// the pair and carry the chroma of the whole 16x8 (8x16) luma pair -- | ||
| 7302 | +/// `setup_pred_plane`'s own `if (subsampling_y && (mi_row & 1) && | ||
| 7303 | +/// mi_size_high[bsize] == 1) mi_row -= 1` offset, i.e. an 8x4 (4x8) chroma | ||
| 7304 | +/// transform at the PAIR's origin, with CfL averaging over the pair's luma. | ||
| 7305 | +/// | ||
| 7306 | +/// Tables: LUMA `TX_16X4`/`TX_4X16` averages to the 8x8 entropy context | ||
| 7307 | +/// ((0 + 2 + 1) >> 1 = 1) with 64 coded positions, so its CDF set is | ||
| 7308 | +/// [`TxbSet::LumaRect16x4`] (`Luma8`'s tables, the `TX_4X4` `tx_type` row); | ||
| 7309 | +/// scans are [`SCAN_16X4`]/[`SCAN_4X16`]. CHROMA `TX_8X4`/`TX_4X8` is | ||
| 7310 | +/// [`TxbSet::ChromaRect8x4`] with [`SCAN_8X4`]/[`SCAN_4X8`]. Angle deltas ARE | ||
| 7311 | +/// coded (`av1_use_angle_delta` compares the BLOCK_SIZES_ALL enum index, and | ||
| 7312 | +/// BLOCK_16X4 is 17), and so is `use_filter_intra` (both sides <= 32) off this | ||
| 7313 | +/// shape's own CDF row. | ||
| 7314 | +/// | ||
| 7315 | +/// A split transform (`tx_depth != 0`, `sub_tx_size_map[TX_16X4] == TX_8X4`) | ||
| 7316 | +/// refuses by name rather than guess-decode. | ||
| 7317 | +#[allow(clippy::too_many_arguments)] | ||
| 7318 | +fn decode_rect4_16( | ||
| 7319 | + dec: &mut SymbolDecoder, | ||
| 7320 | + cdfs: &mut Cdfs, | ||
| 7321 | + neighbours: &mut Neighbours, | ||
| 7322 | + at16: (usize, usize), | ||
| 7323 | + horz: bool, | ||
| 7324 | + y: &mut PlaneBuf, | ||
| 7325 | + u: &mut PlaneBuf, | ||
| 7326 | + v: &mut PlaneBuf, | ||
| 7327 | + enable_filter_intra: bool, | ||
| 7328 | + allow_screen_content_tools: bool, | ||
| 7329 | + base_q_idx: u8, | ||
| 7330 | + tx_select: bool, | ||
| 7331 | + reduced_tx_set: bool, | ||
| 7332 | +) -> Result<()> { | ||
| 7333 | + let (r, c) = at16; | ||
| 7334 | + let (mi_row0, mi_col0) = (r * (SUB / MI), c * (SUB / MI)); | ||
| 7335 | + let (bw, bh) = if horz { (16, 4) } else { (4, 16) }; | ||
| 7336 | + let (mi_w, mi_h) = (bw / MI, bh / MI); | ||
| 7337 | + let scan: &[u16] = if horz { &SCAN_16X4 } else { &SCAN_4X16 }; | ||
| 7338 | + let chroma_scan: &[u16] = if horz { &SCAN_8X4 } else { &SCAN_4X8 }; | ||
| 7339 | + let mut prev: Option<((usize, usize), usize)> = None; | ||
| 7340 | + let mut last_mode = DC_PRED; | ||
| 7341 | + let mut last_uv_mode = DC_PRED; | ||
| 7342 | + for i in 0..4usize { | ||
| 7343 | + let lmi = if horz { | ||
| 7344 | + (mi_row0 + i, mi_col0) | ||
| 7345 | + } else { | ||
| 7346 | + (mi_row0, mi_col0 + i) | ||
| 7347 | + }; | ||
| 7348 | + let has_chroma = i % 2 == 1; | ||
| 7349 | + // `decode_block_rect4`'s own neighbour rule: the coarse 16-px cell | ||
| 7350 | + // aliases all four strips onto one entry, so the mi-exact map wins and | ||
| 7351 | + // the previous strip stands in on the split axis. | ||
| 7352 | + let mut above_mode = neighbours.above_mode[c]; | ||
| 7353 | + let mut left_mode = neighbours.left_mode[r]; | ||
| 7354 | + if let Some(((pr, pc), pmode)) = prev { | ||
| 7355 | + if pc == lmi.1 && lmi.0 == pr + mi_h { | ||
| 7356 | + above_mode = pmode; | ||
| 7357 | + } else if pr == lmi.0 && lmi.1 == pc + mi_w { | ||
| 7358 | + left_mode = pmode; | ||
| 7359 | + } | ||
| 7360 | + } | ||
| 7361 | + let (above_mode, left_mode) = | ||
| 7362 | + neighbours.modes_above_left_mi(lmi.0, lmi.1, (above_mode, left_mode)); | ||
| 7363 | + let ( | ||
| 7364 | + skip, | ||
| 7365 | + mode, | ||
| 7366 | + angle_delta_y, | ||
| 7367 | + uv_mode, | ||
| 7368 | + angle_delta_uv, | ||
| 7369 | + alpha, | ||
| 7370 | + filter_intra, | ||
| 7371 | + palette_y, | ||
| 7372 | + palette_uv, | ||
| 7373 | + ) = read_intra_mode_rect( | ||
| 7374 | + dec, | ||
| 7375 | + cdfs, | ||
| 7376 | + above_mode, | ||
| 7377 | + left_mode, | ||
| 7378 | + true, | ||
| 7379 | + has_chroma, | ||
| 7380 | + bw, | ||
| 7381 | + bh, | ||
| 7382 | + enable_filter_intra, | ||
| 7383 | + neighbours.skip_txfm_ctx(lmi.0, lmi.1), | ||
| 7384 | + allow_screen_content_tools, | ||
| 7385 | + None, | ||
| 7386 | + &[], | ||
| 7387 | + lmi.0, | ||
| 7388 | + lmi.1, | ||
| 7389 | + )?; | ||
| 7390 | + if palette_y.is_some() || palette_uv.is_some() { | ||
| 7391 | + return Err(unsupported( | ||
| 7392 | + "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", | ||
| 7393 | + )); | ||
| 7394 | + } | ||
| 7395 | + let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); | ||
| 7396 | + if smooth_neighbor { | ||
| 7397 | + SMOOTH_LUMA_HITS.with(|h| h.set(h.get() + 1)); | ||
| 7398 | + } | ||
| 7399 | + if filter_intra.is_some() { | ||
| 7400 | + FILTER_INTRA_RECT_HITS.with(|h| h.set(h.get() + 1)); | ||
| 7401 | + } | ||
| 7402 | + // `bsize_to_tx_size_cat(BLOCK_16X4)`: `max_txsize_rect_lookup` is | ||
| 7403 | + // TX_16X4 and `sub_tx_size_map` reaches TX_4X4 in two steps, so the | ||
| 7404 | + // depth symbol is the 3-symbol `tx_size_cat1` -- not the 2-symbol | ||
| 7405 | + // `cat0` a 4x8 leaf reads nor the `cat2` a 32x8 strip does. | ||
| 7406 | + let depth = if tx_select { | ||
| 7407 | + let ctx = tx_size_context_rect(neighbours, lmi, bw, bh); | ||
| 7408 | + dec.symbol(&mut cdfs.tx_size_cat1[ctx]) | ||
| 7409 | + } else { | ||
| 7410 | + 0 | ||
| 7411 | + }; | ||
| 7412 | + if depth != 0 { | ||
| 7413 | + TX_DEPTH_HITS.with(|h| h.set(h.get() + 1)); | ||
| 7414 | + RECT4_16_SPLIT_HITS.with(|h| h.set(h.get() + 1)); | ||
| 7415 | + } | ||
| 7416 | + let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth); | ||
| 7417 | + let (px, py) = (lmi.1 * MI, lmi.0 * MI); | ||
| 7418 | + let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); | ||
| 7419 | + neighbours.record_mode_mi(lmi.0, lmi.1, mi_w, mi_h, mode); | ||
| 7420 | + if depth != 0 { | ||
| 7421 | + // [`decode_rect_split`]'s per-unit walk, inlined because the | ||
| 7422 | + // CHROMA of this shape belongs to the strip's 4:2:0 pair, not to | ||
| 7423 | + // the strip (that function codes one chroma transform per block). | ||
| 7424 | + // depth 1 is the 2:1 rect unit TX_8X4/TX_4X8 | ||
| 7425 | + // (`sub_tx_size_map[TX_16X4]`), depth 2 the square TX_4X4; each | ||
| 7426 | + // unit predicts off the units before it in raster order. | ||
| 7427 | + let rect_unit = tx_w != tx_h; | ||
| 7428 | + let zero_tu = vec![0i32; tx_w * tx_h]; | ||
| 7429 | + for tu_row in 0..bh / tx_h { | ||
| 7430 | + for tu_col in 0..bw / tx_w { | ||
| 7431 | + let tu_mi = (lmi.0 + tu_row * (tx_h / MI), lmi.1 + tu_col * (tx_w / MI)); | ||
| 7432 | + let (tu_px, tu_py) = (px + tu_col * tx_w, py + tu_row * tx_h); | ||
| 7433 | + let tu_reach = Reach::of_tu( | ||
| 7434 | + bw, | ||
| 7435 | + bh, | ||
| 7436 | + tu_col * tx_w, | ||
| 7437 | + tu_row * tx_h, | ||
| 7438 | + tx_w, | ||
| 7439 | + tx_h, | ||
| 7440 | + reach, | ||
| 7441 | + ); | ||
| 7442 | + if skip { | ||
| 7443 | + y.reconstruct_rect( | ||
| 7444 | + tu_px, tu_py, tx_w, tx_h, mode, angle_delta_y, tu_reach, &zero_tu, | ||
| 7445 | + None, filter_intra, smooth_neighbor, | ||
| 7446 | + ); | ||
| 7447 | + neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &zero_tu); | ||
| 7448 | + } else if rect_unit { | ||
| 7449 | + // `get_txsize_entropy_ctx(TX_8X4)` is the 8x8 class with | ||
| 7450 | + // 32 coded positions and the `TX_4X4` `tx_type` row: | ||
| 7451 | + // exactly [`TxbSet::LumaRect4x8`]. | ||
| 7452 | + let tu_around = neighbours.around_mi_rect(tu_mi, tx_w, tx_h)[0]; | ||
| 7453 | + let tu_skip_ctx = | ||
| 7454 | + neighbours.luma_skip_ctx_rect(tu_mi, tx_w / MI, tx_h / MI); | ||
| 7455 | + let set = if reduced_tx_set { | ||
| 7456 | + TxbSet::LumaRect4x8 | ||
| 7457 | + } else { | ||
| 7458 | + TxbSet::LumaRect4x8Set1 | ||
| 7459 | + }; | ||
| 7460 | + let tu_scan: &[u16] = if tx_w > tx_h { &SCAN_8X4 } else { &SCAN_4X8 }; | ||
| 7461 | + let mut coding = cdfs.txb(set, fi_tx_row(mode, filter_intra)); | ||
| 7462 | + let (tu_grid, tu_tx_type) = read_coeffs_rect( | ||
| 7463 | + dec, | ||
| 7464 | + &mut coding, | ||
| 7465 | + tu_scan, | ||
| 7466 | + tx_w, | ||
| 7467 | + tx_h, | ||
| 7468 | + tu_skip_ctx, | ||
| 7469 | + dc_sign_ctx(tu_around.2), | ||
| 7470 | + TxType::DctDct, | ||
| 7471 | + )?; | ||
| 7472 | + let residual = dequant_and_inverse_typed_wh( | ||
| 7473 | + &tu_grid, | ||
| 7474 | + tx_w, | ||
| 7475 | + tx_h, | ||
| 7476 | + crate::decode::bit_depth(), | ||
| 7477 | + block_q_idx(), | ||
| 7478 | + plane_q_delta(0).0, | ||
| 7479 | + plane_q_delta(0).1, | ||
| 7480 | + tu_tx_type, | ||
| 7481 | + ); | ||
| 7482 | + y.reconstruct_rect( | ||
| 7483 | + tu_px, tu_py, tx_w, tx_h, mode, angle_delta_y, tu_reach, &residual, | ||
| 7484 | + None, filter_intra, smooth_neighbor, | ||
| 7485 | + ); | ||
| 7486 | + if tu_grid.iter().any(|&l| l != 0) { | ||
| 7487 | + RECT4_16_COEFF_HITS.with(|h| h.set(h.get() + 1)); | ||
| 7488 | + } | ||
| 7489 | + neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &tu_grid); | ||
| 7490 | + } else { | ||
| 7491 | + let tu_around = neighbours.around_mi(tu_mi, tx_w)[0]; | ||
| 7492 | + let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_w / MI); | ||
| 7493 | + let tu_grid = read_plane( | ||
| 7494 | + dec, | ||
| 7495 | + cdfs, | ||
| 7496 | + txbset_for(tx_w, reduced_tx_set), | ||
| 7497 | + &default_scan(tx_w), | ||
| 7498 | + 0, | ||
| 7499 | + tu_around, | ||
| 7500 | + mode, | ||
| 7501 | + mode, | ||
| 7502 | + angle_delta_y, | ||
| 7503 | + tu_reach, | ||
| 7504 | + y, | ||
| 7505 | + tu_px, | ||
| 7506 | + tu_py, | ||
| 7507 | + tx_w, | ||
| 7508 | + tx_w, | ||
| 7509 | + base_q_idx, | ||
| 7510 | + None, | ||
| 7511 | + filter_intra, | ||
| 7512 | + Some(tu_skip_ctx), | ||
| 7513 | + smooth_neighbor, | ||
| 7514 | + )?; | ||
| 7515 | + if tu_grid.iter().any(|&l| l != 0) { | ||
| 7516 | + RECT4_16_COEFF_HITS.with(|h| h.set(h.get() + 1)); | ||
| 7517 | + } | ||
| 7518 | + neighbours.record_mi_luma(tu_mi, tx_w, &tu_grid); | ||
| 7519 | + } | ||
| 7520 | + } | ||
| 7521 | + } | ||
| 7522 | + } else { | ||
| 7523 | + let levels = if skip { | ||
| 7524 | + let zeros = vec![0i32; bw * bh]; | ||
| 7525 | + y.reconstruct_rect( | ||
| 7526 | + px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra, | ||
| 7527 | + smooth_neighbor, | ||
| 7528 | + ); | ||
| 7529 | + zeros | ||
| 7530 | + } else { | ||
| 7531 | + // The strip's luma TU *is* the strip (`plane_bsize == | ||
| 7532 | + // txsize_to_bsize[tx_size]`), so `get_txb_ctx` fixes | ||
| 7533 | + // `txb_skip_ctx` at 0. | ||
| 7534 | + let around = neighbours.around_mi_rect(lmi, bw, bh)[0]; | ||
| 7535 | + let set = if reduced_tx_set { | ||
| 7536 | + TxbSet::LumaRect16x4 | ||
| 7537 | + } else { | ||
| 7538 | + TxbSet::LumaRect16x4Set1 | ||
| 7539 | + }; | ||
| 7540 | + let mut coding = cdfs.txb(set, fi_tx_row(mode, filter_intra)); | ||
| 7541 | + let (levels, tx_type) = read_coeffs_rect( | ||
| 7542 | + dec, | ||
| 7543 | + &mut coding, | ||
| 7544 | + scan, | ||
| 7545 | + bw, | ||
| 7546 | + bh, | ||
| 7547 | + 0, | ||
| 7548 | + dc_sign_ctx(around.2), | ||
| 7549 | + TxType::DctDct, | ||
| 7550 | + )?; | ||
| 7551 | + let residual = dequant_and_inverse_typed_wh( | ||
| 7552 | + &levels, | ||
| 7553 | + bw, | ||
| 7554 | + bh, | ||
| 7555 | + crate::decode::bit_depth(), | ||
| 7556 | + block_q_idx(), | ||
| 7557 | + plane_q_delta(0).0, | ||
| 7558 | + plane_q_delta(0).1, | ||
| 7559 | + tx_type, | ||
| 7560 | + ); | ||
| 7561 | + y.reconstruct_rect( | ||
| 7562 | + px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra, | ||
| 7563 | + smooth_neighbor, | ||
| 7564 | + ); | ||
| 7565 | + RECT4_16_COEFF_HITS.with(|h| h.set(h.get() + 1)); | ||
| 7566 | + levels | ||
| 7567 | + }; | ||
| 7568 | + neighbours.record_mi_luma_rect(lmi, bw, bh, &levels); | ||
| 7569 | + } | ||
| 7570 | + neighbours.fill_skip_grid_rect(lmi, mi_w, mi_h, skip); | ||
| 7571 | + neighbours.fill_lf_grid_rect(lmi, mi_w, mi_h, tx_w as u8, tx_h as u8, 0); | ||
| 7572 | + // `update_partition_context` writes `partition_context_lookup[ | ||
| 7573 | + // BLOCK_16X4]` over the whole 16x16: full width above, a 4-px side on | ||
| 7574 | + // the left (mirrored under VERT_4). | ||
| 7575 | + for cell in 0..mi_w { | ||
| 7576 | + if let Some(slot) = neighbours.above_side_mi.get_mut(lmi.1 + cell) { | ||
| 7577 | + *slot = bw; | ||
| 7578 | + } | ||
| 7579 | + } | ||
| 7580 | + for cell in 0..mi_h { | ||
| 7581 | + if let Some(slot) = neighbours.left_side_mi.get_mut(lmi.0 + cell) { | ||
| 7582 | + *slot = bh; | ||
| 7583 | + } | ||
| 7584 | + } | ||
| 7585 | + if has_chroma { | ||
| 7586 | + RECT4_16_CHROMA_HITS.with(|h| h.set(h.get() + 1)); | ||
| 7587 | + let pair_mi = if horz { | ||
| 7588 | + (lmi.0 - 1, lmi.1) | ||
| 7589 | + } else { | ||
| 7590 | + (lmi.0, lmi.1 - 1) | ||
| 7591 | + }; | ||
| 7592 | + let (pw, ph) = if horz { (16, 8) } else { (8, 16) }; | ||
| 7593 | + let (ppx, ppy) = (pair_mi.1 * MI, pair_mi.0 * MI); | ||
| 7594 | + let (cpx, cpy) = (ppx / 2, ppy / 2); | ||
| 7595 | + let (cw, ch) = (pw / 2, ph / 2); | ||
| 7596 | + let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; | ||
| 7597 | + let pair_reach = Reach::of_rect(pw, ph, ppx, ppy, y.width, y.height); | ||
| 7598 | + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c); | ||
| 7599 | + let (u_levels, v_levels) = if skip { | ||
| 7600 | + let zeros = vec![0i32; cw * ch]; | ||
| 7601 | + for (buf, _plane) in [(&mut *u, 1usize), (&mut *v, 2)] { | ||
| 7602 | + buf.reconstruct_rect( | ||
| 7603 | + cpx, | ||
| 7604 | + cpy, | ||
| 7605 | + cw, | ||
| 7606 | + ch, | ||
| 7607 | + uv_predict_mode, | ||
| 7608 | + angle_delta_uv, | ||
| 7609 | + pair_reach, | ||
| 7610 | + &zeros, | ||
| 7611 | + None, | ||
| 7612 | + None, | ||
| 7613 | + smooth_neighbor_uv, | ||
| 7614 | + ); | ||
| 7615 | + } | ||
| 7616 | + (zeros.clone(), zeros) | ||
| 7617 | + } else { | ||
| 7618 | + let around = neighbours.around_mi_rect(pair_mi, pw, ph); | ||
| 7619 | + let mut planes = Vec::with_capacity(2); | ||
| 7620 | + for plane in 1..3 { | ||
| 7621 | + let default_tx = default_intra_tx_type(uv_predict_mode as u8); | ||
| 7622 | + let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1); | ||
| 7623 | + let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); | ||
| 7624 | + let (levels, tx_type) = read_coeffs_rect( | ||
| 7625 | + dec, | ||
| 7626 | + &mut coding, | ||
| 7627 | + chroma_scan, | ||
| 7628 | + cw, | ||
| 7629 | + ch, | ||
| 7630 | + skip_ctx, | ||
| 7631 | + dc_sign_ctx(around[plane].2), | ||
| 7632 | + default_tx, | ||
| 7633 | + )?; | ||
| 7634 | + planes.push((levels, tx_type)); | ||
| 7635 | + } | ||
| 7636 | + let (v_levels, v_tx_type) = planes.pop().expect("plane 2"); | ||
| 7637 | + let (u_levels, u_tx_type) = planes.pop().expect("plane 1"); | ||
| 7638 | + // CfL averages the luma of the WHOLE pair, the region this one | ||
| 7639 | + // chroma transform covers. | ||
| 7640 | + let ac = alpha.map(|_| cfl_ac_q3_rect(y, ppx, ppy, pw, ph)); | ||
| 7641 | + for (plane, buf, levels, tx_type) in [ | ||
| 7642 | + (1usize, &mut *u, &u_levels, u_tx_type), | ||
| 7643 | + (2, &mut *v, &v_levels, v_tx_type), | ||
| 7644 | + ] { | ||
| 7645 | + let residual = dequant_and_inverse_typed_wh( | ||
| 7646 | + levels, | ||
| 7647 | + cw, | ||
| 7648 | + ch, | ||
| 7649 | + crate::decode::bit_depth(), | ||
| 7650 | + block_q_idx(), | ||
| 7651 | + plane_q_delta(plane).0, | ||
| 7652 | + plane_q_delta(plane).1, | ||
| 7653 | + tx_type, | ||
| 7654 | + ); | ||
| 7655 | + buf.reconstruct_rect( | ||
| 7656 | + cpx, | ||
| 7657 | + cpy, | ||
| 7658 | + cw, | ||
| 7659 | + ch, | ||
| 7660 | + uv_predict_mode, | ||
| 7661 | + angle_delta_uv, | ||
| 7662 | + pair_reach, | ||
| 7663 | + &residual, | ||
| 7664 | + alpha | ||
| 7665 | + .zip(ac.as_deref()) | ||
| 7666 | + .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), | ||
| 7667 | + None, | ||
| 7668 | + smooth_neighbor_uv, | ||
| 7669 | + ); | ||
| 7670 | + } | ||
| 7671 | + (u_levels, v_levels) | ||
| 7672 | + }; | ||
| 7673 | + neighbours.record_uv_mode_mi(pair_mi.0, pair_mi.1, pw / MI, ph / MI, uv_predict_mode); | ||
| 7674 | + // The chroma planes' coefficient context, over the PAIR's mi span | ||
| 7675 | + // (`decode_leaf_rect8`'s own rule: a subsampled plane's bound is | ||
| 7676 | + // the luma one rounded up to its 4x4 unit). | ||
| 7677 | + let u_state = neighbour_state(&u_levels); | ||
| 7678 | + let v_state = neighbour_state(&v_levels); | ||
| 7679 | + let round_up_even = |n: usize| n.div_ceil(2) * 2; | ||
| 7680 | + let bound_h = round_up_even(neighbours.mi_rows); | ||
| 7681 | + let bound_w = round_up_even(neighbours.mi_cols); | ||
| 7682 | + for cell in 0..(ph / MI) { | ||
| 7683 | + if pair_mi.0 + cell < bound_h | ||
| 7684 | + && let Some(slot) = neighbours.left.get_mut(pair_mi.0 + cell) | ||
| 7685 | + { | ||
| 7686 | + slot[1] = u_state; | ||
| 7687 | + slot[2] = v_state; | ||
| 7688 | + } | ||
| 7689 | + } | ||
| 7690 | + for cell in 0..(pw / MI) { | ||
| 7691 | + if pair_mi.1 + cell < bound_w | ||
| 7692 | + && let Some(slot) = neighbours.above.get_mut(pair_mi.1 + cell) | ||
| 7693 | + { | ||
| 7694 | + slot[1] = u_state; | ||
| 7695 | + slot[2] = v_state; | ||
| 7696 | + } | ||
| 7697 | + } | ||
| 7698 | + last_uv_mode = uv_predict_mode; | ||
| 7699 | + } | ||
| 7700 | + if horz { | ||
| 7701 | + RECT4_16_HORZ_HITS.with(|h| h.set(h.get() + 1)); | ||
| 7702 | + } else { | ||
| 7703 | + RECT4_16_VERT_HITS.with(|h| h.set(h.get() + 1)); | ||
| 7704 | + } | ||
| 7705 | + last_mode = mode; | ||
| 7706 | + prev = Some((lmi, mode)); | ||
| 7707 | + } | ||
| 7708 | + // The coarse 16-px cell holds one entry for the whole 16x16: the last | ||
| 7709 | + // strip is what a block below (right) sees through it, the mi-exact maps | ||
| 7710 | + // above answering everything finer. | ||
| 7711 | + neighbours.above_mode[c] = last_mode; | ||
| 7712 | + neighbours.left_mode[r] = last_mode; | ||
| 7713 | + neighbours.above_uv_mode[c] = last_uv_mode; | ||
| 7714 | + neighbours.left_uv_mode[r] = last_uv_mode; | ||
| 7715 | + neighbours.above_side[c] = bw; | ||
| 7716 | + neighbours.left_side[r] = bh; | ||
| 7717 | + Ok(()) | ||
| 7718 | +} | ||
| 7719 | + | ||
| 7234 | /// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/ | 7720 | /// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/ |
| 7235 | /// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` / | 7721 | /// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` / |
| 7236 | /// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike | 7722 | /// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike |
| @@ -7284,6 +7770,7 @@ fn decode_block_rect64( | |||
| 7284 | // the real 13-symbol `uv_mode_no_cfl` one and desynced the tile | 7770 | // the real 13-symbol `uv_mode_no_cfl` one and desynced the tile |
| 7285 | // from this block's very first symbol (lane-sbpart r3 bisect). | 7771 | // from this block's very first symbol (lane-sbpart r3 bisect). |
| 7286 | false, | 7772 | false, |
| 7773 | + true, | ||
| 7287 | bw, | 7774 | bw, |
| 7288 | bh, | 7775 | bh, |
| 7289 | enable_filter_intra, | 7776 | enable_filter_intra, |
| @@ -10854,7 +11341,19 @@ fn read_block_tx_size( | |||
| 10854 | /// `DTT9_IDTX_1DDCT` row at `tx_size_sqr == TX_8X8`, only reachable through a | 11341 | /// `DTT9_IDTX_1DDCT` row at `tx_size_sqr == TX_8X8`, only reachable through a |
| 10855 | /// rect transform), neither of which exists yet -- both stay refused by name. | 11342 | /// rect transform), neither of which exists yet -- both stay refused by name. |
| 10856 | fn rect_inter_residual_supported(w: usize, h: usize) -> bool { | 11343 | fn rect_inter_residual_supported(w: usize, h: usize) -> bool { |
| 10857 | - matches!((w, h), (32, 16) | (16, 32) | (16, 8) | (8, 16)) | 11344 | + matches!( |
| 11345 | + (w, h), | ||
| 11346 | + // 2:1 strips whose transform is coded in full (lane-inter4). | ||
| 11347 | + (32, 16) | (16, 32) | (16, 8) | (8, 16) | ||
| 11348 | + // lane-r14 r2: strips with a 64-px axis. `av1_get_max_eob` codes | ||
| 11349 | + // only the low 32 coefficients of a 64-length axis, so these read | ||
| 11350 | + // exactly the truncated corner the INTRA superblock-strip path | ||
| 11351 | + // already reads (`read_intra_mode_rect`), through | ||
| 11352 | + // `av1_get_adjusted_tx_size`'s CDF set. Their `tx_size_sqr_up` is | ||
| 11353 | + // `TX_64X64`, so `av1_get_ext_tx_set_type` is `DCT_ONLY` and no | ||
| 11354 | + // `tx_type` symbol is coded at all. | ||
| 11355 | + | (64, 32) | (32, 64) | (64, 16) | (16, 64) | ||
| 11356 | + ) | ||
| 10858 | } | 11357 | } |
| 10859 | 11358 | ||
| 10860 | /// The luma coefficient/`tx_type` table set of a whole-block rectangular | 11359 | /// The luma coefficient/`tx_type` table set of a whole-block rectangular |
| @@ -10875,6 +11374,13 @@ fn rect_inter_luma_set(w: usize, h: usize) -> TxbSet { | |||
| 10875 | TxbSet::LumaRect16x8InterSet1 | 11374 | TxbSet::LumaRect16x8InterSet1 |
| 10876 | } | 11375 | } |
| 10877 | } | 11376 | } |
| 11377 | + // lane-r14 r2: `av1_get_adjusted_tx_size` maps TX_64X32/TX_32X64 to | ||
| 11378 | + // TX_32X32 and TX_64X16/TX_16X64 to TX_32X16/TX_16X32, and | ||
| 11379 | + // `get_txsize_entropy_ctx`/`txsize_log2_minus4` agree with the | ||
| 11380 | + // adjusted size, so the existing sets are bit-exact. Neither carries a | ||
| 11381 | + // `tx_type` table (DCT_ONLY above), so the intra/inter split is moot. | ||
| 11382 | + (64, 32) | (32, 64) => TxbSet::Luma64, | ||
| 11383 | + (64, 16) | (16, 64) => TxbSet::LumaRect32x16, | ||
| 10878 | _ => unreachable!("rect_inter_residual_supported gates every shape that reaches here"), | 11384 | _ => unreachable!("rect_inter_residual_supported gates every shape that reaches here"), |
| 10879 | } | 11385 | } |
| 10880 | } | 11386 | } |
| @@ -10887,6 +11393,13 @@ fn rect_inter_chroma_set(w: usize, h: usize) -> TxbSet { | |||
| 10887 | match (w, h) { | 11393 | match (w, h) { |
| 10888 | (16, 8) | (8, 16) => TxbSet::ChromaRect16x8, | 11394 | (16, 8) | (8, 16) => TxbSet::ChromaRect16x8, |
| 10889 | (8, 4) | (4, 8) => TxbSet::ChromaRect8x4, | 11395 | (8, 4) | (4, 8) => TxbSet::ChromaRect8x4, |
| 11396 | + // lane-r14 r2: chroma of a 64-axis strip -- 32x16/16x32 under a | ||
| 11397 | + // 64x32/32x64 one, 32x8/8x32 under a 64x16/16x64 one. Neither chroma | ||
| 11398 | + // unit has a 64-px axis, so both are coded in full; `Chroma16` is the | ||
| 11399 | + // exact set for TX_32X8/TX_8X32 (`get_txsize_entropy_ctx` = TX_16X16, | ||
| 11400 | + // `txsize_log2_minus4` = 4), same as the intra strip path uses. | ||
| 11401 | + (32, 16) | (16, 32) => TxbSet::ChromaRect32x16, | ||
| 11402 | + (32, 8) | (8, 32) => TxbSet::Chroma16, | ||
| 10890 | _ => unreachable!("rect_inter_residual_supported gates every shape that reaches here"), | 11403 | _ => unreachable!("rect_inter_residual_supported gates every shape that reaches here"), |
| 10891 | } | 11404 | } |
| 10892 | } | 11405 | } |
| @@ -10932,6 +11445,8 @@ fn rect_scan(w: usize, h: usize) -> &'static [u16] { | |||
| 10932 | (8, 16) => &SCAN_8X16, | 11445 | (8, 16) => &SCAN_8X16, |
| 10933 | (8, 4) => &SCAN_8X4, | 11446 | (8, 4) => &SCAN_8X4, |
| 10934 | (4, 8) => &SCAN_4X8, | 11447 | (4, 8) => &SCAN_4X8, |
| 11448 | + (32, 8) => &SCAN_32X8, | ||
| 11449 | + (8, 32) => &SCAN_8X32, | ||
| 10935 | _ => unreachable!("rect_inter_residual_supported gates every shape that reaches here"), | 11450 | _ => unreachable!("rect_inter_residual_supported gates every shape that reaches here"), |
| 10936 | } | 11451 | } |
| 10937 | } | 11452 | } |
| @@ -10998,6 +11513,16 @@ fn read_block_tx_size_rect( | |||
| 10998 | } | 11513 | } |
| 10999 | TXFM_SPLIT_HITS.with(|c| c.set(c.get() + 1)); | 11514 | TXFM_SPLIT_HITS.with(|c| c.set(c.get() + 1)); |
| 11000 | RECT_INTER_TXSPLIT_HITS.with(|c| c.set(c.get() + 1)); | 11515 | RECT_INTER_TXSPLIT_HITS.with(|c| c.set(c.get() + 1)); |
| 11516 | + // lane-r14 r2: `sub_tx_size_map` is square for every shape this decoder | ||
| 11517 | + // splits (TX_32X16 -> TX_16X16, TX_64X32 -> TX_32X32) EXCEPT the 1:4 | ||
| 11518 | + // strips with a 64-px axis, where it stays rectangular | ||
| 11519 | + // (TX_64X16 -> TX_32X16, TX_16X64 -> TX_16X32) and the square recursion | ||
| 11520 | + // below would code the wrong tree. | ||
| 11521 | + if tx_w.max(tx_h) == 64 && tx_w.min(tx_h) == 16 { | ||
| 11522 | + return Err(unsupported( | ||
| 11523 | + "a split transform on a 1:4 inter strip with a 64-px axis", | ||
| 11524 | + )); | ||
| 11525 | + } | ||
| 11001 | let sub = tx_w.min(tx_h); | 11526 | let sub = tx_w.min(tx_h); |
| 11002 | let max_w_mi = (bw / MI).min(mi_cols.saturating_sub(at_mi.1)); | 11527 | let max_w_mi = (bw / MI).min(mi_cols.saturating_sub(at_mi.1)); |
| 11003 | let max_h_mi = (bh / MI).min(mi_rows.saturating_sub(at_mi.0)); | 11528 | let max_h_mi = (bh / MI).min(mi_rows.saturating_sub(at_mi.0)); |
| @@ -11061,16 +11586,50 @@ fn read_inter_plane_rect( | |||
| 11061 | Some(t) if w.max(h) < 32 => t, | 11586 | Some(t) if w.max(h) < 32 => t, |
| 11062 | _ => TxType::DctDct, | 11587 | _ => TxType::DctDct, |
| 11063 | }; | 11588 | }; |
| 11064 | - let (grid, tx_type) = read_coeffs_rect( | 11589 | + // lane-r14 r2: a 64-length axis codes only its low 32 coefficients |
| 11590 | + // (`av1_get_max_eob`), so the coded unit is the `min(w,32) x min(h,32)` | ||
| 11591 | + // corner, zero-extended into the true `w x h` grid before the inverse | ||
| 11592 | + // transform -- exactly what the intra superblock-strip path does. A | ||
| 11593 | + // corner that comes out square (32x32, under a 64x32/32x64 strip) reads | ||
| 11594 | + // through the SQUARE coefficient reader with `rect_shape = Some((w, h))`, | ||
| 11595 | + // because `av1_nz_map_ctx_offset` is indexed by the real, un-adjusted | ||
| 11596 | + // rectangular shape (lane-sbpart r8). | ||
| 11597 | + let (cw, ch) = (w.min(32), h.min(32)); | ||
| 11598 | + if plane_idx == 0 && w.max(h) == 64 { | ||
| 11599 | + RECT64_INTER_TU_HITS.with(|c| c.set(c.get() + 1)); | ||
| 11600 | + } | ||
| 11601 | + let (corner, tx_type) = if (cw, ch) == (32, 32) { | ||
| 11602 | + let scan32 = default_scan(TX32); | ||
| 11603 | + read_coeffs( | ||
| 11065 | dec, | 11604 | dec, |
| 11066 | &mut coding, | 11605 | &mut coding, |
| 11067 | - rect_scan(w, h), | 11606 | + &scan32, |
| 11068 | - w, | ||
| 11069 | - h, | ||
| 11070 | skip_ctx, | 11607 | skip_ctx, |
| 11071 | dc_sign_ctx(around.2), | 11608 | dc_sign_ctx(around.2), |
| 11072 | default_tx_type, | 11609 | default_tx_type, |
| 11073 | - )?; | 11610 | + Some((w, h)), |
| 11611 | + )? | ||
| 11612 | + } else { | ||
| 11613 | + read_coeffs_rect( | ||
| 11614 | + dec, | ||
| 11615 | + &mut coding, | ||
| 11616 | + rect_scan(cw, ch), | ||
| 11617 | + cw, | ||
| 11618 | + ch, | ||
| 11619 | + skip_ctx, | ||
| 11620 | + dc_sign_ctx(around.2), | ||
| 11621 | + default_tx_type, | ||
| 11622 | + )? | ||
| 11623 | + }; | ||
| 11624 | + let grid = if (cw, ch) == (w, h) { | ||
| 11625 | + corner | ||
| 11626 | + } else { | ||
| 11627 | + let mut full = vec![0i32; w * h]; | ||
| 11628 | + for row in 0..ch { | ||
| 11629 | + full[row * w..][..cw].copy_from_slice(&corner[row * cw..][..cw]); | ||
| 11630 | + } | ||
| 11631 | + full | ||
| 11632 | + }; | ||
| 11074 | let (dc_delta, ac_delta) = plane_q_delta(plane_idx); | 11633 | let (dc_delta, ac_delta) = plane_q_delta(plane_idx); |
| 11075 | let residual = dequant_and_inverse_typed_wh( | 11634 | let residual = dequant_and_inverse_typed_wh( |
| 11076 | &grid, | 11635 | &grid, |
| @@ -12640,11 +13199,34 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 12640 | neighbours.left_mode[sr] = mode_right; | 13199 | neighbours.left_mode[sr] = mode_right; |
| 12641 | continue; | 13200 | continue; |
| 12642 | } | 13201 | } |
| 12643 | - if part16 != PARTITION_SPLIT { | 13202 | + if part16 == PARTITION_HORZ_4 |
| 12644 | - return Err(unsupported( | 13203 | + || part16 == PARTITION_VERT_4 |
| 12645 | - "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)", | 13204 | + { |
| 12646 | - )); | 13205 | + decode_rect4_16( |
| 13206 | + &mut dec, | ||
| 13207 | + &mut cdfs, | ||
| 13208 | + &mut neighbours, | ||
| 13209 | + at16, | ||
| 13210 | + part16 == PARTITION_HORZ_4, | ||
| 13211 | + &mut y, | ||
| 13212 | + &mut u, | ||
| 13213 | + &mut v, | ||
| 13214 | + enable_filter_intra, | ||
| 13215 | + allow_screen_content_tools, | ||
| 13216 | + base_q_idx, | ||
| 13217 | + tx_select, | ||
| 13218 | + reduced_tx_set, | ||
| 13219 | + )?; | ||
| 13220 | + continue; | ||
| 12647 | } | 13221 | } |
| 13222 | + // lane-r14 r2 (verifier note): every | ||
| 13223 | + // one of the 10 symbols this CDF can | ||
| 13224 | + // produce is handled above, so SPLIT | ||
| 13225 | + // is the only value that reaches | ||
| 13226 | + // here -- the refusal that used to | ||
| 13227 | + // stand here was unreachable and is | ||
| 13228 | + // gone from `refusal_inventory`. | ||
| 13229 | + debug_assert_eq!(part16, PARTITION_SPLIT); | ||
| 12648 | // A real (non-straddle) SPLIT of a | 13230 | // A real (non-straddle) SPLIT of a |
| 12649 | // whole 16x16 into four 8x8 leaves -- | 13231 | // whole 16x16 into four 8x8 leaves -- |
| 12650 | // the same recursion the straddle | 13232 | // the same recursion the straddle |
| @@ -21526,8 +22108,6 @@ mod tests { | |||
| 21526 | // string that blocks the shape otherwise. Either way the row is | 22108 | // string that blocks the shape otherwise. Either way the row is |
| 21527 | // pinned HERE, so the round that lifts one of those refusals cannot | 22109 | // pinned HERE, so the round that lifts one of those refusals cannot |
| 21528 | // land a wrong CDF row for the shape it unlocks. | 22110 | // land a wrong CDF row for the shape it unlocks. |
| 21529 | - const PART16: &str = "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes \ | ||
| 21530 | - only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)"; | ||
| 21531 | let libaom: &[(usize, usize, u16, Option<&str>)] = &[ | 22111 | let libaom: &[(usize, usize, u16, Option<&str>)] = &[ |
| 21532 | (4, 4, 4621, None), | 22112 | (4, 4, 4621, None), |
| 21533 | (4, 8, 6743, None), | 22113 | (4, 8, 6743, None), |
| @@ -21542,8 +22122,10 @@ mod tests { | |||
| 21542 | // The 1:4 strips: a 16x16-level PARTITION_HORZ_4/VERT_4 gives | 22122 | // The 1:4 strips: a 16x16-level PARTITION_HORZ_4/VERT_4 gives |
| 21543 | // 4x16/16x4 (still refused by name before any leaf is coded), | 22123 | // 4x16/16x4 (still refused by name before any leaf is coded), |
| 21544 | // a 32x32-level one 8x32/32x8. | 22124 | // a 32x32-level one 8x32/32x8. |
| 21545 | - (4, 16, 12770, Some(PART16)), | 22125 | + // lane-r14: the 16-level pair is coded now (`decode_rect4_16`), |
| 21546 | - (16, 4, 10368, Some(PART16)), | 22126 | + // owning classes 13/12. |
| 22127 | + (4, 16, 12770, None), | ||
| 22128 | + (16, 4, 10368, None), | ||
| 21547 | // lane-fi32x8 r1: the 32-level pair is coded (four 32x8/8x32 | 22129 | // lane-fi32x8 r1: the 32-level pair is coded (four 32x8/8x32 |
| 21548 | // strips per `PARTITION_HORZ_4`/`VERT_4`) and now owns classes | 22130 | // strips per `PARTITION_HORZ_4`/`VERT_4`) and now owns classes |
| 21549 | // 10/11; only the 16-level pair is still refused before any leaf. | 22131 | // 10/11; only the 16-level pair is still refused before any leaf. |
| @@ -22018,8 +22600,16 @@ mod tests { | |||
| 22018 | // non-skip, so the named refusal is the rectangular-inter-residual | 22600 | // non-skip, so the named refusal is the rectangular-inter-residual |
| 22019 | // one. Either string proves what the pin was written for: a non-SPLIT | 22601 | // one. Either string proves what the pin was written for: a non-SPLIT |
| 22020 | // superblock never silently decodes as SPLIT. | 22602 | // superblock never silently decodes as SPLIT. |
| 22603 | + // lane-r14 r2: the rectangular-residual refusal is gone (a 64x32 strip | ||
| 22604 | + // now codes its truncated low-32 coefficient corner), so this | ||
| 22605 | + // hand-written fixture walks further still and stops on the limit of | ||
| 22606 | + // the FIXTURE rather than of the decoder: it names no reference | ||
| 22607 | + // pictures. All three strings prove the one thing this pin exists for | ||
| 22608 | + // -- a non-SPLIT superblock never silently decodes as SPLIT. | ||
| 22021 | assert!( | 22609 | assert!( |
| 22022 | - msg.contains("SPLIT") || msg.contains("rectangular residual coding"), | 22610 | + msg.contains("SPLIT") |
| 22611 | + || msg.contains("rectangular residual coding") | ||
| 22612 | + || msg.contains("no picture at this frame's own ref_frame_idx slot"), | ||
| 22023 | "expected the named inter-SB-partition refusal, got: {msg}" | 22613 | "expected the named inter-SB-partition refusal, got: {msg}" |
| 22024 | ); | 22614 | ); |
| 22025 | } | 22615 | } |
crates/ec-av1/src/refusal_inventory.rsmodified+4 -1
| @@ -34,7 +34,6 @@ 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)", | ||
| 38 | "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", | 37 | "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", | 38 | "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", | 39 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| @@ -81,6 +80,10 @@ const REFUSALS: &[&str] = &[ | |||
| 81 | "warp prediction with a scaled reference (superres, unimplemented)", | 80 | "warp prediction with a scaled reference (superres, unimplemented)", |
| 82 | "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", | 81 | "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", |
| 83 | "a motion_mode symbol for a block shape with no CDF row here", | 82 | "a motion_mode symbol for a block shape with no CDF row here", |
| 83 | + // lane-r14 r2: the whole-transform case of every 64-axis inter strip is | ||
| 84 | + // coded; only the SPLIT of a 1:4 strip with a 64-px axis is left, whose | ||
| 85 | + // `sub_tx_size_map` entry is rectangular (TX_64X16 -> TX_32X16). | ||
| 86 | + "a split transform on a 1:4 inter strip with a 64-px axis", | ||
| 84 | ]; | 87 | ]; |
| 85 | 88 | ||
| 86 | /// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than | 89 | /// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than |
crates/ec-av1/src/stream.rsmodified+276 -0
| @@ -68,6 +68,12 @@ pub fn inter_rect_counters() -> (usize, usize, usize, usize, usize, usize) { | |||
| 68 | ) | 68 | ) |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | +/// lane-r14 r2: luma transform units of an inter strip with a 64-px axis, | ||
| 72 | +/// coded as the truncated low-32 coefficient corner. | ||
| 73 | +pub fn rect64_inter_tu_hits() -> usize { | ||
| 74 | + crate::decode::rect64_inter_tu_hits() | ||
| 75 | +} | ||
| 76 | + | ||
| 71 | pub fn rect4_32_counters() -> (usize, usize, usize) { | 77 | pub fn rect4_32_counters() -> (usize, usize, usize) { |
| 72 | ( | 78 | ( |
| 73 | crate::decode::rect4_32_horz_hits(), | 79 | crate::decode::rect4_32_horz_hits(), |
| @@ -6558,10 +6564,21 @@ mod tests { | |||
| 6558 | // NON-skip, so it stops at "a non-skip rectangular (HORZ/VERT/HORZ_B) | 6564 | // NON-skip, so it stops at "a non-skip rectangular (HORZ/VERT/HORZ_B) |
| 6559 | // strip needs rectangular residual coding". The 10-bit twin below is | 6565 | // strip needs rectangular residual coding". The 10-bit twin below is |
| 6560 | // `#[ignore]`d with that exact reason rather than deleted or weakened. | 6566 | // `#[ignore]`d with that exact reason rather than deleted or weakened. |
| 6567 | + // lane-r14 r2 re-measured the 8-bit-only note above: the residual | ||
| 6568 | + // refusal it names is GONE (this round codes a 64-px transform axis as | ||
| 6569 | + // its truncated low-32 corner), and a 10-bit sweep of this exact | ||
| 6570 | + // recipe now reaches the arm -- 2 pixel-exact attempts, 2 64x32 and 2 | ||
| 6571 | + // 32x64 strips, 2 of them carrying a coded 64-axis residual. It stays | ||
| 6572 | + // 8-bit here for a DIFFERENT, newly exposed reason: 10-bit attempt 14 | ||
| 6573 | + // (cq 61, horizontal split, motion step 12) mismatches ffmpeg while | ||
| 6574 | + // decoding ZERO superblock-level rect strips and zero 64-axis | ||
| 6575 | + // residual units, i.e. a defect of some other shape that this gate | ||
| 6576 | + // must not absorb. See lanes/r14-r2.report.md. | ||
| 6561 | for bit_depth in [8u32] { | 6577 | for bit_depth in [8u32] { |
| 6562 | let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) = | 6578 | let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) = |
| 6563 | (0u32, 0u32, 0u32, 0u32); | 6579 | (0u32, 0u32, 0u32, 0u32); |
| 6564 | let (mut horz_proved, mut vert_proved) = (0usize, 0usize); | 6580 | let (mut horz_proved, mut vert_proved) = (0usize, 0usize); |
| 6581 | + let mut rect64_tus = 0usize; | ||
| 6565 | for attempt in 0..16u32 { | 6582 | for attempt in 0..16u32 { |
| 6566 | // Two orientations (the transposed pair a one-sided gate could | 6583 | // Two orientations (the transposed pair a one-sided gate could |
| 6567 | // never separate) x four quantisers x two motion steps: which | 6584 | // never separate) x four quantisers x two motion steps: which |
| @@ -6634,6 +6651,7 @@ mod tests { | |||
| 6634 | ); | 6651 | ); |
| 6635 | let stream = out.stdout; | 6652 | let stream = out.stdout; |
| 6636 | let before = crate::stream::inter_rect_counters(); | 6653 | let before = crate::stream::inter_rect_counters(); |
| 6654 | + let rect64_before = crate::stream::rect64_inter_tu_hits(); | ||
| 6637 | let frames = match decode_stream(&stream) { | 6655 | let frames = match decode_stream(&stream) { |
| 6638 | Err(e) => { | 6656 | Err(e) => { |
| 6639 | let msg = e.to_string(); | 6657 | let msg = e.to_string(); |
| @@ -6650,6 +6668,7 @@ mod tests { | |||
| 6650 | }; | 6668 | }; |
| 6651 | let after = crate::stream::inter_rect_counters(); | 6669 | let after = crate::stream::inter_rect_counters(); |
| 6652 | let (horz, vert) = (after.2 - before.2, after.3 - before.3); | 6670 | let (horz, vert) = (after.2 - before.2, after.3 - before.3); |
| 6671 | + let rect64 = crate::stream::rect64_inter_tu_hits() - rect64_before; | ||
| 6653 | let ffmpeg_frames = if bit_depth == 10 { | 6672 | let ffmpeg_frames = if bit_depth == 10 { |
| 6654 | ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | 6673 | ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) |
| 6655 | } else { | 6674 | } else { |
| @@ -6678,11 +6697,13 @@ mod tests { | |||
| 6678 | } | 6697 | } |
| 6679 | horz_proved += horz; | 6698 | horz_proved += horz; |
| 6680 | vert_proved += vert; | 6699 | vert_proved += vert; |
| 6700 | + rect64_tus += rect64; | ||
| 6681 | matched += 1; | 6701 | matched += 1; |
| 6682 | } | 6702 | } |
| 6683 | eprintln!( | 6703 | eprintln!( |
| 6684 | "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \ | 6704 | "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \ |
| 6685 | attempts carrying the arm, 64x32 strips={horz_proved}, 32x64 strips={vert_proved}, \ | 6705 | attempts carrying the arm, 64x32 strips={horz_proved}, 32x64 strips={vert_proved}, \ |
| 6706 | + 64-axis residual TUs={rect64_tus}, \ | ||
| 6686 | {out_of_scope} attempts carried none ({oos_mismatch} of them mismatched)" | 6707 | {out_of_scope} attempts carried none ({oos_mismatch} of them mismatched)" |
| 6687 | ); | 6708 | ); |
| 6688 | assert_eq!( | 6709 | assert_eq!( |
| @@ -6690,6 +6711,15 @@ mod tests { | |||
| 6690 | "{NAME}: {oos_mismatch} attempt(s) with no superblock-level inter rect strip \ | 6711 | "{NAME}: {oos_mismatch} attempt(s) with no superblock-level inter rect strip \ |
| 6691 | decoded but mismatched ffmpeg -- a defect of another shape, not a pass" | 6712 | decoded but mismatched ffmpeg -- a defect of another shape, not a pass" |
| 6692 | ); | 6713 | ); |
| 6714 | + // lane-r14 r2: the residual half of the arm -- a strip that is not | ||
| 6715 | + // `skip` and codes a real 64-axis transform unit. Without this the | ||
| 6716 | + // gate proves only the partition symbol. | ||
| 6717 | + assert!( | ||
| 6718 | + rect64_tus > 0, | ||
| 6719 | + "{NAME} ({bit_depth}-bit): no superblock-level rect strip carried a coded \ | ||
| 6720 | + 64-axis residual transform unit inside a pixel-exact attempt \ | ||
| 6721 | + (horz={horz_proved}, vert={vert_proved}) -- the residual arm proved nothing" | ||
| 6722 | + ); | ||
| 6693 | assert!( | 6723 | assert!( |
| 6694 | horz_proved + vert_proved > 0, | 6724 | horz_proved + vert_proved > 0, |
| 6695 | "{NAME} ({bit_depth}-bit): the superblock-level inter rect arm never fired \ | 6725 | "{NAME} ({bit_depth}-bit): the superblock-level inter rect arm never fired \ |
| @@ -20014,6 +20044,252 @@ mod tests { | |||
| 20014 | /// then compared pixel-exact are counted (class | 20044 | /// then compared pixel-exact are counted (class |
| 20015 | /// gate-skips-on-its-own-failure); the 10-bit arm is what retires | 20045 | /// gate-skips-on-its-own-failure); the 10-bit arm is what retires |
| 20016 | /// `enable-1to4-partitions` from `NEVER_EXERCISED_10BIT`. | 20046 | /// `enable-1to4-partitions` from `NEVER_EXERCISED_10BIT`. |
| 20047 | + /// lane-r14: the 16x16-level 1:4 pair -- four 16x4 (`PARTITION_HORZ_4`) or | ||
| 20048 | + /// 4x16 (`PARTITION_VERT_4`) strips, the shape the wall | ||
| 20049 | + /// "a 1:4 partition below 16x16" refused. Fixture: 4-PIXEL bands (the | ||
| 20050 | + /// 8-pixel ones of the 32-level gate above, one size down -- a 16x4 strip | ||
| 20051 | + /// is flat where a 16x8 one is not), transposed per attempt so a | ||
| 20052 | + /// transposed scan or nz-map table cannot pass (class | ||
| 20053 | + /// scan-weights-cross-axis), plus an explicit-seed noise layer that keeps | ||
| 20054 | + /// aomenc out of screen-content mode. `--enable-filter-intra=1` and | ||
| 20055 | + /// is ON: this shape reads `use_filter_intra` off its own CDF rows | ||
| 20056 | + /// (classes 12/13). The `--enable-tx-size-search=1` half of the window | ||
| 20057 | + /// splits the strip's transform (depth 1 = TX_8X4/TX_4X8, depth 2 = | ||
| 20058 | + /// TX_4X4). | ||
| 20059 | + /// | ||
| 20060 | + /// Counters: 16x4 strips, 4x16 strips, chroma-reference strips (the odd | ||
| 20061 | + /// strip of each 4:2:0 pair, the only one that codes chroma) and strips | ||
| 20062 | + /// with a coded residual must all be nonzero over the compared attempts, | ||
| 20063 | + /// and only attempts that DECODED and were compared pixel-exact count | ||
| 20064 | + /// (class gate-skips-on-its-own-failure). | ||
| 20065 | + #[test] | ||
| 20066 | + fn a_real_aomenc_stream_with_a_16_level_1to4_partition_decodes_pixel_exact() { | ||
| 20067 | + const NAME: &str = | ||
| 20068 | + "a_real_aomenc_stream_with_a_16_level_1to4_partition_decodes_pixel_exact"; | ||
| 20069 | + let _gate_lock = lock_gate_counters(); | ||
| 20070 | + if !have_ffmpeg() { | ||
| 20071 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 20072 | + return; | ||
| 20073 | + } | ||
| 20074 | + if !have_aomenc() { | ||
| 20075 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 20076 | + return; | ||
| 20077 | + } | ||
| 20078 | + let (width, height, frame_count) = (192usize, 128usize, 1usize); | ||
| 20079 | + let n_attempts: u32 = std::env::var("EC_R14_GATE_ATTEMPTS") | ||
| 20080 | + .ok() | ||
| 20081 | + .and_then(|s| s.parse().ok()) | ||
| 20082 | + .unwrap_or(8); | ||
| 20083 | + for bit_depth in [8u32, 10u32] { | ||
| 20084 | + let mut named_refusals = 0u32; | ||
| 20085 | + let mut matched = 0u32; | ||
| 20086 | + let (mut horz_proved, mut vert_proved) = (0usize, 0usize); | ||
| 20087 | + let (mut chroma_proved, mut coeff_proved) = (0usize, 0usize); | ||
| 20088 | + let mut split_proved = 0usize; | ||
| 20089 | + let (mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32); | ||
| 20090 | + // The second half of the window turns `--enable-tx-size-search` on: | ||
| 20091 | + // that is what makes a 16x4 strip SPLIT its transform (depth 1 = | ||
| 20092 | + // TX_8X4, depth 2 = TX_4X4), the arm the first half never reaches. | ||
| 20093 | + for attempt in 0..n_attempts * 2 { | ||
| 20094 | + let tx_search = attempt >= n_attempts; | ||
| 20095 | + let attempt = attempt % n_attempts; | ||
| 20096 | + let seed = 42 + attempt; | ||
| 20097 | + let duration = frame_count as f64 / 25.0; | ||
| 20098 | + let axis = if attempt % 2 == 0 { "Y" } else { "X" }; | ||
| 20099 | + let step = 67 + (attempt / 2) * 12; | ||
| 20100 | + let noise = 6 + (attempt % 4) * 3; | ||
| 20101 | + let source = format!( | ||
| 20102 | + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ | ||
| 20103 | + geq=lum='mod(floor({axis}/4)*{step},256)',\ | ||
| 20104 | + noise=alls={noise}:all_seed={seed},format=yuv420p" | ||
| 20105 | + ); | ||
| 20106 | + let cq_level = format!("--cq-level={}", 24 + (attempt % 4) * 8); | ||
| 20107 | + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 20108 | + let y4m = Command::new("ffmpeg") | ||
| 20109 | + .args([ | ||
| 20110 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), | ||
| 20111 | + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | ||
| 20112 | + ]) | ||
| 20113 | + .stdin(Stdio::null()) | ||
| 20114 | + .stdout(Stdio::piped()) | ||
| 20115 | + .stderr(Stdio::piped()) | ||
| 20116 | + .output() | ||
| 20117 | + .expect("ffmpeg failed to run"); | ||
| 20118 | + assert!( | ||
| 20119 | + y4m.status.success(), | ||
| 20120 | + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", | ||
| 20121 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 20122 | + ); | ||
| 20123 | + let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 20124 | + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 20125 | + let args: Vec<&str> = vec![ | ||
| 20126 | + "--codec=av1", | ||
| 20127 | + "--passes=1", | ||
| 20128 | + "--end-usage=q", | ||
| 20129 | + &cq_level, | ||
| 20130 | + "--cpu-used=0", | ||
| 20131 | + "--threads=1", | ||
| 20132 | + "--row-mt=0", | ||
| 20133 | + "--sb-size=64", | ||
| 20134 | + &depth_arg, | ||
| 20135 | + &input_depth_arg, | ||
| 20136 | + "--enable-rect-partitions=1", | ||
| 20137 | + "--enable-ab-partitions=0", | ||
| 20138 | + "--enable-1to4-partitions=1", | ||
| 20139 | + "--min-partition-size=4", | ||
| 20140 | + "--max-partition-size=16", | ||
| 20141 | + "--enable-restoration=0", | ||
| 20142 | + "--enable-palette=0", | ||
| 20143 | + "--deltaq-mode=0", | ||
| 20144 | + "--enable-filter-intra=1", | ||
| 20145 | + // lane-r14: CfL stays OFF here. This shape's CfL averages | ||
| 20146 | + // the luma of the whole PAIR and is written, but no gate | ||
| 20147 | + // asserts a CfL hit counter (there is none), and passing | ||
| 20148 | + // `=1` would retire `enable-cfl-intra` from | ||
| 20149 | + // `gate_coverage::NEVER_EXERCISED_*` on a flag alone -- | ||
| 20150 | + // exactly the false coverage that list exists to prevent. | ||
| 20151 | + "--enable-cfl-intra=0", | ||
| 20152 | + "--enable-intrabc=0", | ||
| 20153 | + if tx_search { | ||
| 20154 | + "--enable-tx-size-search=1" | ||
| 20155 | + } else { | ||
| 20156 | + "--enable-tx-size-search=0" | ||
| 20157 | + }, | ||
| 20158 | + "--obu", | ||
| 20159 | + "-o", | ||
| 20160 | + "-", | ||
| 20161 | + "-", | ||
| 20162 | + ]; | ||
| 20163 | + let mut child = Command::new(aomenc_path()) | ||
| 20164 | + .args(&args) | ||
| 20165 | + .stdin(Stdio::piped()) | ||
| 20166 | + .stdout(Stdio::piped()) | ||
| 20167 | + .stderr(Stdio::piped()) | ||
| 20168 | + .spawn() | ||
| 20169 | + .expect("aomenc failed to start"); | ||
| 20170 | + child | ||
| 20171 | + .stdin | ||
| 20172 | + .take() | ||
| 20173 | + .expect("aomenc stdin") | ||
| 20174 | + .write_all(&y4m.stdout) | ||
| 20175 | + .expect("writing y4m to aomenc"); | ||
| 20176 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 20177 | + assert!( | ||
| 20178 | + out.status.success(), | ||
| 20179 | + "aomenc refused the fixture: {}", | ||
| 20180 | + String::from_utf8_lossy(&out.stderr) | ||
| 20181 | + ); | ||
| 20182 | + let stream = out.stdout; | ||
| 20183 | + let before = crate::decode::rect4_16_counters(); | ||
| 20184 | + let frames = match decode_stream(&stream) { | ||
| 20185 | + Err(e) => { | ||
| 20186 | + let msg = e.to_string(); | ||
| 20187 | + assert!( | ||
| 20188 | + msg.contains("unsupported"), | ||
| 20189 | + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, seed \ | ||
| 20190 | + {seed}): {msg}" | ||
| 20191 | + ); | ||
| 20192 | + named_refusals += 1; | ||
| 20193 | + eprintln!("{bit_depth}-bit seed {seed} refusal: {msg}"); | ||
| 20194 | + continue; | ||
| 20195 | + } | ||
| 20196 | + Ok(frames) => frames, | ||
| 20197 | + }; | ||
| 20198 | + let now = crate::decode::rect4_16_counters(); | ||
| 20199 | + let (horz, vert, chroma, coeff, split) = ( | ||
| 20200 | + now.0 - before.0, | ||
| 20201 | + now.1 - before.1, | ||
| 20202 | + now.2 - before.2, | ||
| 20203 | + now.3 - before.3, | ||
| 20204 | + now.4 - before.4, | ||
| 20205 | + ); | ||
| 20206 | + let ffmpeg_frames = if bit_depth == 10 { | ||
| 20207 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 20208 | + } else { | ||
| 20209 | + ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 20210 | + }; | ||
| 20211 | + assert_eq!(frames.len(), frame_count); | ||
| 20212 | + let mismatched = frames | ||
| 20213 | + .iter() | ||
| 20214 | + .zip(&ffmpeg_frames) | ||
| 20215 | + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | ||
| 20216 | + if horz + vert == 0 { | ||
| 20217 | + out_of_scope += 1; | ||
| 20218 | + if mismatched { | ||
| 20219 | + out_of_scope_mismatch += 1; | ||
| 20220 | + eprintln!( | ||
| 20221 | + "{NAME}: {bit_depth}-bit seed {seed} MISMATCHES with zero 16-level \ | ||
| 20222 | + 1:4 strips -- a pre-existing defect of another shape" | ||
| 20223 | + ); | ||
| 20224 | + } | ||
| 20225 | + continue; | ||
| 20226 | + } | ||
| 20227 | + if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { | ||
| 20228 | + std::fs::write(&path, &stream).expect("writing pinned stream"); | ||
| 20229 | + eprintln!( | ||
| 20230 | + "EC_AV1_GATE_DUMP: wrote mismatching stream ({bit_depth}-bit, seed \ | ||
| 20231 | + {seed}) to {path}" | ||
| 20232 | + ); | ||
| 20233 | + } | ||
| 20234 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 20235 | + assert_eq!( | ||
| 20236 | + got.y, want.y, | ||
| 20237 | + "{NAME} frame {i} luma vs ffmpeg ({bit_depth}-bit, seed {seed})" | ||
| 20238 | + ); | ||
| 20239 | + assert_eq!( | ||
| 20240 | + got.u, want.u, | ||
| 20241 | + "{NAME} frame {i} U vs ffmpeg ({bit_depth}-bit, seed {seed})" | ||
| 20242 | + ); | ||
| 20243 | + assert_eq!( | ||
| 20244 | + got.v, want.v, | ||
| 20245 | + "{NAME} frame {i} V vs ffmpeg ({bit_depth}-bit, seed {seed})" | ||
| 20246 | + ); | ||
| 20247 | + } | ||
| 20248 | + horz_proved += horz; | ||
| 20249 | + vert_proved += vert; | ||
| 20250 | + chroma_proved += chroma; | ||
| 20251 | + coeff_proved += coeff; | ||
| 20252 | + split_proved += split; | ||
| 20253 | + matched += 1; | ||
| 20254 | + } | ||
| 20255 | + assert!( | ||
| 20256 | + matched > 0, | ||
| 20257 | + "{NAME}: every {bit_depth}-bit attempt refused or fell out of scope ({named_refusals} \ | ||
| 20258 | + refusals, {out_of_scope} out of scope); the gate proved nothing" | ||
| 20259 | + ); | ||
| 20260 | + assert_eq!( | ||
| 20261 | + out_of_scope_mismatch, 0, | ||
| 20262 | + "{NAME}: {out_of_scope_mismatch} {bit_depth}-bit attempt(s) mismatch with no \ | ||
| 20263 | + 16-level 1:4 strip at all" | ||
| 20264 | + ); | ||
| 20265 | + assert!( | ||
| 20266 | + horz_proved > 0 && vert_proved > 0, | ||
| 20267 | + "{NAME}: {bit_depth}-bit compared attempts decoded {horz_proved} 16x4 and \ | ||
| 20268 | + {vert_proved} 4x16 strips -- both orientations must fire or a transposed table \ | ||
| 20269 | + passes" | ||
| 20270 | + ); | ||
| 20271 | + assert!( | ||
| 20272 | + chroma_proved > 0, | ||
| 20273 | + "{NAME}: {bit_depth}-bit compared attempts closed {chroma_proved} chroma pairs" | ||
| 20274 | + ); | ||
| 20275 | + assert!( | ||
| 20276 | + coeff_proved > 0, | ||
| 20277 | + "{NAME}: {bit_depth}-bit compared attempts coded no residual on any strip" | ||
| 20278 | + ); | ||
| 20279 | + assert!( | ||
| 20280 | + split_proved > 0, | ||
| 20281 | + "{NAME}: {bit_depth}-bit compared attempts never split a strip's transform -- \ | ||
| 20282 | + the `--enable-tx-size-search=1` half of the window proved nothing" | ||
| 20283 | + ); | ||
| 20284 | + eprintln!( | ||
| 20285 | + "{NAME}: {bit_depth}-bit {matched} compared attempts, {horz_proved} 16x4 / \ | ||
| 20286 | + {vert_proved} 4x16 strips, {chroma_proved} chroma pairs, {coeff_proved} coded \ | ||
| 20287 | + units, {split_proved} split-transform strips, {named_refusals} refusals, \ | ||
| 20288 | + {out_of_scope} out of scope" | ||
| 20289 | + ); | ||
| 20290 | + } | ||
| 20291 | + } | ||
| 20292 | + | ||
| 20017 | #[test] | 20293 | #[test] |
| 20018 | // lane-tx64x16 r4: the fixture r3 could not find. `gradients` never wins | 20294 | // lane-tx64x16 r4: the fixture r3 could not find. `gradients` never wins |
| 20019 | // a 32-level 1:4 shape; 8-pixel BANDS do -- each 32x8 strip is flat, so | 20295 | // a 32-level 1:4 shape; 8-pixel BANDS do -- each 32x8 strip is flat, so |
lanes/r14-r1.report.mdadded+119 -0
| @@ -0,0 +1,119 @@ | |||
| 1 | +# lane-r14 r1 -- the 16x16-level 1:4 partition (four 16x4 / 4x16 strips) | ||
| 2 | + | ||
| 3 | +Branch `lane-r14` off main `0df090a`; commits `9bde843` (partition + paired | ||
| 4 | +chroma) and `ccd58a2` (split transform). | ||
| 5 | + | ||
| 6 | +## Film first | ||
| 7 | + | ||
| 8 | +`ffmpeg -ss 300 -t 0.4 -i <the 4K 10-bit AV1 mkv> -c:v copy -f obu kf300.obu`, | ||
| 9 | +then `decode_probe`: | ||
| 10 | + | ||
| 11 | +* BEFORE: `REFUSED: a 1:4 partition below 16x16 (PARTITION_HORZ_4/VERT_4, four | ||
| 12 | + 16x4/4x16 strips ...)`. | ||
| 13 | +* AFTER 9bde843: `REFUSED: a 16x4/4x16 strip whose transform is split` -- every | ||
| 14 | + 16-level 1:4 strip in that key frame reads `tx_depth != 0`, so the partition | ||
| 15 | + alone was not enough. | ||
| 16 | +* AFTER ccd58a2: `REFUSED: a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs | ||
| 17 | + rectangular residual coding` -- ANOTHER lane's wall; the 1:4 one is gone, with | ||
| 18 | + rect4_32 counters horz=104 vert=172 coded=238 (these are the 32-level 1:4 counters decode_probe prints, NOT rect4_16; the true rect4_16 numbers on kf300 are 96, 148, 122, 311, 63) strips decoded at the 32 level alone before it stops. | ||
| 19 | + | ||
| 20 | +EVIDENCE: /tmp/claude-1000/-home-user-Documents-Code-Rust-edith-codecs/b6d8a07f-96a4-4bbb-b378-af9ae25cf7c9/scratchpad/r14/kf300.obu | decode_probe before/after each commit | refusal string moved 1:4-partition -> 1:4-split-transform -> rect-residual (another lane) | ||
| 21 | + | ||
| 22 | +## What changed | ||
| 23 | + | ||
| 24 | +* `crates/ec-av1/src/decode.rs` -- `decode_rect4_16` (new): the four strips of a | ||
| 25 | + 16-level `PARTITION_HORZ_4`/`VERT_4`, wired at the key-frame 16-level | ||
| 26 | + partition site (the old refusal is now | ||
| 27 | + "a 16x16-level partition value outside PARTITION_NONE..PARTITION_VERT_4", | ||
| 28 | + the SB-level wording one size down). | ||
| 29 | + - CHROMA is what is new at this size: `is_chroma_reference` is false for a | ||
| 30 | + 4:2:0 block one mi tall (wide) on an EVEN mi row (column), so strips 0 and 2 | ||
| 31 | + read no `uv_mode`/`cfl_alpha`/`angle_delta_uv` and code no chroma; strips 1 | ||
| 32 | + and 3 close the pair and carry the 8x4 (4x8) chroma of the whole 16x8 (8x16) | ||
| 33 | + luma pair at the PAIR's origin (`setup_pred_plane`'s `mi_row -= 1`), CfL | ||
| 34 | + averaging the pair's luma. | ||
| 35 | + - `read_intra_mode_rect` grew a `has_chroma` (`is_chroma_reference`) parameter; | ||
| 36 | + the four existing call sites pass `true`. | ||
| 37 | + - Split transform: `decode_rect_split`'s per-unit walk inlined (its chroma is | ||
| 38 | + the block's, ours is the pair's). depth 1 = TX_8X4/TX_4X8 rect units | ||
| 39 | + (`TxbSet::LumaRect4x8`), depth 2 = square TX_4X4 via `read_plane`. | ||
| 40 | + - `filter_intra_size_class_rect`: classes 12/13 for 16x4/4x16. | ||
| 41 | + - `palette_bsize_ctx_wh`: DEFECT SWEPT -- `av1_allow_palette`'s | ||
| 42 | + `sb_type >= BLOCK_8X8` is an ENUM INDEX test that BLOCK_4X16 (16) and | ||
| 43 | + BLOCK_16X4 (17) clear, so a 64-pixel 1:4 strip DOES read `palette_y_mode` | ||
| 44 | + (ctx 0) in a screen-content frame; the old "both sides >= 8" bound dropped | ||
| 45 | + that symbol. Now `bw <= 64 && bh <= 64 && bw * bh >= 64`, which reproduces | ||
| 46 | + the enum-index rule for every shape. | ||
| 47 | +* `crates/ec-av1/src/cdf.rs` -- `FILTER_INTRA` rows 12/13 (10368/12770), the | ||
| 48 | + values `filter_intra_classes_carry_their_own_libaom_default_row` already | ||
| 49 | + pinned for BLOCK_16X4/BLOCK_4X16; that test now lists both as owning a class. | ||
| 50 | +* `crates/ec-av1/src/cdf_state.rs` -- `TxbSet::LumaRect16x4{,Set1}`: `Luma8`'s | ||
| 51 | + coefficient tables (`get_txsize_entropy_ctx(TX_16X4)` = the 8x8 class, 64 | ||
| 52 | + positions) with the `TX_4X4` `tx_type` row. | ||
| 53 | +* `crates/ec-av1/src/refusal_inventory.rs` -- the 1:4-below-16x16 refusal is | ||
| 54 | + gone; the 16-level partition-value guard replaces it. | ||
| 55 | +* `crates/ec-av1/src/stream.rs` -- the gate. | ||
| 56 | + | ||
| 57 | +## Gate | ||
| 58 | + | ||
| 59 | +`a_real_aomenc_stream_with_a_16_level_1to4_partition_decodes_pixel_exact` | ||
| 60 | +(4-pixel bands, transposed per attempt, explicit-seed noise, 192x128, | ||
| 61 | +`--enable-1to4-partitions=1 --enable-rect-partitions=1 --enable-ab-partitions=0 | ||
| 62 | +--min-partition-size=4 --max-partition-size=16 --enable-filter-intra=1 | ||
| 63 | +--cpu-used=0`, second half of the window `--enable-tx-size-search=1`), 8 seeds x | ||
| 64 | +2 tx-search arms x 2 bit depths. | ||
| 65 | + | ||
| 66 | +``` | ||
| 67 | +systemd-run --user --scope -q -p MemoryMax=8G env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-r14 \ | ||
| 68 | + EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 nice -n 10 cargo test -p ec-av1 --lib -j3 \ | ||
| 69 | + a_real_aomenc_stream_with_a_16_level_1to4 -- --nocapture | ||
| 70 | +``` | ||
| 71 | + | ||
| 72 | +Result (both green): | ||
| 73 | + | ||
| 74 | +* 8-bit: 15 compared attempts, 192 16x4 / 288 4x16 strips, 240 chroma pairs, | ||
| 75 | + 486 coded units, 102 split-transform strips, 0 refusals, 1 out of scope. | ||
| 76 | +* 10-bit: 16 compared attempts, 148 16x4 / 280 4x16 strips, 214 chroma pairs, | ||
| 77 | + 433 coded units, 82 split-transform strips, 0 refusals, 0 out of scope. | ||
| 78 | + | ||
| 79 | +Every decoded frame is pixel-compared against ffmpeg (`assert_eq` on all three | ||
| 80 | +planes); a decode error is asserted to be a NAMED refusal, never a SKIP. | ||
| 81 | + | ||
| 82 | +EVIDENCE: cargo test output above | 31 real aomenc streams encoded, decoded and compared | 340 16x4 + 568 4x16 strips, 454 chroma pairs, 184 split-transform strips, 0 mismatches | ||
| 83 | + | ||
| 84 | +Encoder-side proof the shape is really in the stream (independent of our | ||
| 85 | +counters): instrumented `aomdec EC_TRACE=1` on the same recipe prints | ||
| 86 | +`EC_PART bsize=6 value=8` (HORZ_4 at BLOCK_16X16) 6x and `value=9` (VERT_4) | ||
| 87 | +10x on the two axes of the fixture. | ||
| 88 | + | ||
| 89 | +## Refusals | ||
| 90 | + | ||
| 91 | +* LIFTED: "a 1:4 partition below 16x16 (PARTITION_HORZ_4/VERT_4, four 16x4/4x16 | ||
| 92 | + strips ...)". | ||
| 93 | +* STILL REFUSED at this shape: "a 1:4 rect strip that actually uses a palette" | ||
| 94 | + (shared with the 32-level pair; reconstruction unported). | ||
| 95 | +* NEW (replacing the lifted one, same site): "a 16x16-level partition value | ||
| 96 | + outside PARTITION_NONE..PARTITION_VERT_4". | ||
| 97 | + | ||
| 98 | +## Residue | ||
| 99 | + | ||
| 100 | +* deferred: the INTER twin of this partition (the inter 16-level site still | ||
| 101 | + refuses 1:4 by its own name) -- unblocked by an inter fixture that reaches a | ||
| 102 | + 16-level 1:4, out of this lane's intra scope. | ||
| 103 | +* deferred: CfL over the pair is written but no gate proves it fired -- | ||
| 104 | + `--enable-cfl-intra` stays `=0` on this recipe because there is no CfL hit | ||
| 105 | + counter, and enabling the flag alone would falsely retire the tool from | ||
| 106 | + `gate_coverage::NEVER_EXERCISED_*`. Unblocked by a CfL counter + a fixture | ||
| 107 | + whose chroma actually correlates with luma. | ||
| 108 | +* accepted: no `--tile-columns` arm in this gate -- the lane added no per-mi | ||
| 109 | + neighbour map, it reuses the existing tile-edge-guarded ones. | ||
| 110 | + | ||
| 111 | +## Suite | ||
| 112 | + | ||
| 113 | +`systemd-run --user --unit=r14-suite3 -p MemoryMax=10G --same-dir bash -lc | ||
| 114 | +'EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-r14 | ||
| 115 | +nice -n 10 cargo test -p ec-av1 --lib -j3'` -> `test result: ok. 356 passed; 0 | ||
| 116 | +failed; 29 ignored` (346 s), log `$HOME/.cache/r14-suite-clean.log`. Siblings | ||
| 117 | +re-run inside it: the 32-level and superblock-level 1:4 gates, every rect-strip | ||
| 118 | +and split-transform gate, `filter_intra_classes_carry_their_own_libaom_default_row`, | ||
| 119 | +`refusal_inventory`, `gate_coverage`, `every_rect_shape`, `base_ctx_rect_offsets`. | ||
lanes/r14-r2.report.mdadded+97 -0
| @@ -0,0 +1,97 @@ | |||
| 1 | +# lane-r14 round 2 — 64-axis rectangular INTER residual coding | ||
| 2 | + | ||
| 3 | +## Per-segment table (ReelB 2160p HDR10, `-c:v copy -an -f obu`, 2 s each) | ||
| 4 | + | ||
| 5 | +| segment | refusal BEFORE this round (at merged main) | refusal AFTER this round | counters | | ||
| 6 | +|---|---|---|---| | ||
| 7 | +| `-ss 300 -t 2` (`seg300.obu`, 206 frame headers) | an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet | *unchanged* (same string, same site `decode.rs:17325`) | rect_inter tu=28 txsplit=18 | | ||
| 8 | +| `-ss 3000 -t 2` (`seg3000.obu`, 288 frame headers) | a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding — shape **32x64** at mi(0,32) | a split transform on a 1:4 inter strip with a 64-px axis | 22 SB-level 32x64 strips decoded, tu=21, txsplit=4 | | ||
| 9 | +| `-ss 4500 -t 2` (`seg4500.obu`, 213 frame headers) | a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding — shape **16x64** at mi(0,0) | a split transform on a 1:4 inter strip with a 64-px axis | txsplit=1 | | ||
| 10 | + | ||
| 11 | +`kf300.obu` (the r1 blocker): the `git merge main` of this round already advanced it past | ||
| 12 | +"a non-skip rectangular ... needs rectangular residual coding" to the intra-rect-strip refusal — | ||
| 13 | +lane-inter4's merge lifted it, the charter's premise was stale. It is **not** one key frame: | ||
| 14 | +`decode_probe` parses 206 frame headers in it. (`ffmpeg -i kf300.obu -bsf:v trace_headers` | ||
| 15 | +prints nothing at all for a bare `.obu` — no container, so the bitstream filter is never | ||
| 16 | +attached; the header count from our own parser is the measurement used instead.) | ||
| 17 | + | ||
| 18 | +## What changed | ||
| 19 | + | ||
| 20 | +- `crates/ec-av1/src/decode.rs:10891 rect_inter_residual_supported` — accepts `(64,32) (32,64) (64,16) (16,64)`. | ||
| 21 | +- `crates/ec-av1/src/decode.rs:10903 rect_inter_luma_set` — `TxbSet::Luma64` for 64x32/32x64, | ||
| 22 | + `TxbSet::LumaRect32x16` for 64x16/16x64 (`av1_get_adjusted_tx_size`; both sets carry | ||
| 23 | + `tx_type: None`, correct because `tx_size_sqr_up == TX_64X64` makes the ext-tx set DCT_ONLY, | ||
| 24 | + so no `tx_type` symbol is coded and the intra/inter table split is moot). | ||
| 25 | +- `crates/ec-av1/src/decode.rs:10921 rect_inter_chroma_set` — 32x16/16x32 → `ChromaRect32x16`, | ||
| 26 | + 32x8/8x32 → `Chroma16` (same sets the INTRA superblock-strip path already uses). | ||
| 27 | +- `crates/ec-av1/src/decode.rs rect_scan` — `SCAN_32X8` / `SCAN_8X32` arms. | ||
| 28 | +- `crates/ec-av1/src/decode.rs read_inter_plane_rect` — the load-bearing change: a 64-length axis | ||
| 29 | + codes only its low 32 coefficients, so the unit read is the `min(w,32) x min(h,32)` corner, | ||
| 30 | + zero-extended into the true `w x h` grid before `dequant_and_inverse_typed_wh`. A square 32x32 | ||
| 31 | + corner goes through the SQUARE reader with `rect_shape = Some((w, h))`, because | ||
| 32 | + `av1_nz_map_ctx_offset` is indexed by the real un-adjusted shape (class from lane-sbpart r8). | ||
| 33 | +- `crates/ec-av1/src/decode.rs read_block_tx_size_rect` — NEW named refusal | ||
| 34 | + `"a split transform on a 1:4 inter strip with a 64-px axis"`: `sub_tx_size_map` is square for | ||
| 35 | + every shape this decoder splits (TX_32X16→TX_16X16, TX_64X32→TX_32X32) except TX_64X16→TX_32X16 | ||
| 36 | + and TX_16X64→TX_16X32, where the existing square recursion would code the wrong tree. | ||
| 37 | +- `crates/ec-av1/src/decode.rs` + `stream.rs:60` — `rect64_inter_tu_hits()` counter (luma 64-axis TUs). | ||
| 38 | +- `crates/ec-av1/src/refusal_inventory.rs` — the new refusal registered. | ||
| 39 | +- `crates/ec-av1/src/stream.rs` gate | ||
| 40 | + `a_real_aomenc_inter_sequence_with_a_superblock_level_rect_partition_decodes_pixel_exact` | ||
| 41 | + now hard-asserts `rect64_tus > 0` (the residual half of the arm; before, the gate proved only | ||
| 42 | + the partition symbol because every strip it accepted was `skip`). | ||
| 43 | + | ||
| 44 | +Merge commit `399278b` resolved the single conflict (`cdf_state.rs` TxbSet match) by keeping BOTH | ||
| 45 | +sides' arms (lane's 16x4 intra 1:4, main's 16x8 inter rect). | ||
| 46 | + | ||
| 47 | +## Gates | ||
| 48 | + | ||
| 49 | +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -- --test-threads=1 superblock_level_rect_partition` | ||
| 50 | + | ||
| 51 | +EVIDENCE: gate stderr | real aomenc 192x128x6, `--enable-rect-partitions=1 --min-partition-size=32 --max-partition-size=64 --sb-size=64`, 16 attempts, every decoded frame compared Y+U+V vs ffmpeg | 8-bit: 2 named refusals, 4 pixel-exact attempts carrying the arm, 64x32 strips=4, 32x64 strips=4, **64-axis residual TUs=2**, 10 out of scope (0 mismatched) — test result: ok | ||
| 52 | + | ||
| 53 | +EVIDENCE: same gate run with `for bit_depth in [8u32, 10u32]` | identical recipe at `--bit-depth=10` | 10-bit: 2 pixel-exact attempts carrying the arm, 64x32=2, 32x64=2, **64-axis residual TUs=2** — the capability is pixel-exact at 10 bits too | ||
| 54 | + | ||
| 55 | +EVIDENCE: `cargo run --example decode_probe -- seg3000.obu` before/after, `EC_AV1_RECT_DUMP=1` | 2 s of the real film at 50:00 | `EC_RECT_REFUSE ... w=32 h=64` → no `EC_RECT_REFUSE` line at all; 22 SB-level 32x64 strips now decode | ||
| 56 | + | ||
| 57 | +Merge-verification gates (on `399278b`): `16_level_1to4 superblock_level_ 32x32_level_1to4 | ||
| 58 | +inter_sequence refusal_inventory gate_coverage` → 38 passed, 0 failed, 4 ignored. | ||
| 59 | + | ||
| 60 | +Full suite: `$HOME/.cache/r14-suite-r2.log`, run on the tip after the second `git merge main` | ||
| 61 | +(main `b51719f`) — totals appended below. | ||
| 62 | + | ||
| 63 | +## Verifier notes folded in (round 2) | ||
| 64 | + | ||
| 65 | +1. `lanes/r14-r1.report.md:18` corrected: the "104 / 172" pair is `decode_probe`'s **rect4_32** | ||
| 66 | + counter line, not rect4_16; the true rect4_16 numbers on `kf300.obu` are 96, 148, 122, 311, 63. | ||
| 67 | +2. `"a 16x16-level partition value outside PARTITION_NONE..PARTITION_VERT_4"` was unreachable | ||
| 68 | + (all 10 symbols of that CDF are handled above the check) — removed from `decode.rs` (now a | ||
| 69 | + `debug_assert_eq!(part16, PARTITION_SPLIT)`) and from `refusal_inventory.rs`. | ||
| 70 | +3. The rectangular-residual wall lives in `decode_inter_block`, reached only from | ||
| 71 | + `decode_inter_frame_tile`, so it fires on an **inter** frame: the key frame of `kf300.obu` | ||
| 72 | + decodes through. **Not measured this round**: the decode-order index of the stopping frame and | ||
| 73 | + a 16-bit byte-equality compare of every frame before it. `decode_probe` reports only the | ||
| 74 | + refusal, and adding the per-frame `cmp` ladder did not fit this round's budget — | ||
| 75 | + deferred(a `decode_probe` mode that dumps every decoded frame before the refusal and diffs it | ||
| 76 | + against `ffmpeg -pix_fmt yuv420p10le`). | ||
| 77 | + | ||
| 78 | +## Residue | ||
| 79 | + | ||
| 80 | +- **deferred**(needs a rect-aware var-tx recursion + rect leaf reconstruction, ~2 call sites): | ||
| 81 | + `a split transform on a 1:4 inter strip with a 64-px axis`. This is the film's next blocker in | ||
| 82 | + BOTH mid-film segments. `sub_tx_size_map[TX_64X16] = TX_32X16` is rectangular, so the leaf | ||
| 83 | + tuple `(row, col, tx_px)` and the two square leaf loops (`decode.rs` ~16174 and ~17150) have to | ||
| 84 | + carry `(row, col, tw, th)`. Out of this round's ≤150-line scope. | ||
| 85 | +- **deferred**(unrelated shape, needs its own bisect): enabling the 10-bit arm of the SB rect gate | ||
| 86 | + exposes a pre-existing mismatch at attempt 14 (cq 61, horizontal split, motion step 12) that | ||
| 87 | + decodes **zero** rect strips and zero 64-axis residual units — provably not this round's code | ||
| 88 | + path. The gate stays `[8u32]` with that measured reason written at the loop instead of the | ||
| 89 | + stale "non-skip residual is refused" one. | ||
| 90 | +- **accepted**: `seg300` still stops at the intra-rect-strip refusal (lane-intrarect's wall, | ||
| 91 | + named and inventoried). | ||
| 92 | + | ||
| 93 | +## Suite | ||
| 94 | + | ||
| 95 | +`systemd-run --user --unit=r14-suite-r2 ... cargo test -p ec-av1 --lib -j3` on tip `c604580` | ||
| 96 | +(after `git merge main` @ `b51719f`) -> **365 passed; 0 failed; 31 ignored**, 623.58s, | ||
| 97 | +log `$HOME/.cache/r14-suite-r2.log`. | ||