32x32-level PARTITION_HORZ_4/VERT_4 -- four 32x8/8x32 strips, mi-granular
Browse files at this commit8e9a081322e413b2033c72ef94278d05007813d5Parent: 30e5597- feat
- 32x32-level PARTITION_HORZ_4/VERT_4 -- four 32x8/8x32 strips, mi-granular
5 changed files +689 -35
- crates/ec-av1/src/cdf_state.rs +22 -0
- crates/ec-av1/src/decode.rs +402 -31
- crates/ec-av1/src/encode.rs +29 -4
- crates/ec-av1/src/refusal_inventory.rs +1 -0
- crates/ec-av1/src/stream.rs +235 -0
crates/ec-av1/src/cdf_state.rsmodified+22 -0
| @@ -108,6 +108,16 @@ pub(crate) enum TxbSet { | |||
| 108 | /// `Luma32`'s 1024-position one. Never carries a `tx_type` symbol: both | 108 | /// `Luma32`'s 1024-position one. Never carries a `tx_type` symbol: both |
| 109 | /// orientations use one variant (`get_tx_set` is `EXT_TX_SET_DCTONLY` at | 109 | /// orientations use one variant (`get_tx_set` is `EXT_TX_SET_DCTONLY` at |
| 110 | /// `tx_size_sqr_up == TX_32X32` regardless of which axis is longer). | 110 | /// `tx_size_sqr_up == TX_32X32` regardless of which axis is longer). |
| 111 | + /// The 32x8/8x32 luma transform of a 32x32-level `PARTITION_HORZ_4`/ | ||
| 112 | + /// `PARTITION_VERT_4` strip (lane-tx64x16 r3). `get_txsize_entropy_ctx` | ||
| 113 | + /// averages the two log2 sides ((5 + 3) / 2 = 4), so the coefficient CDF | ||
| 114 | + /// set is the 16x16 one [`Luma16`](TxbSet::Luma16) reads -- 256 coded | ||
| 115 | + /// positions, `eob_pt_256`. Unlike `Luma16` it carries NO `tx_type` | ||
| 116 | + /// symbol: `tx_size_sqr_up` of a 4:1 32-wide strip is `TX_32X32`, where | ||
| 117 | + /// `av1_get_ext_tx_set_type` returns `EXT_TX_SET_DCTONLY` for an intra | ||
| 118 | + /// block, so the encoder writes none (same reason | ||
| 119 | + /// [`LumaRect32x16`](TxbSet::LumaRect32x16) has none). | ||
| 120 | + LumaRect32x8, | ||
| 111 | LumaRect32x16, | 121 | LumaRect32x16, |
| 112 | /// The chroma 16x8/8x16 transform under the same strip (lane-rectwire): | 122 | /// The chroma 16x8/8x16 transform under the same strip (lane-rectwire): |
| 113 | /// [`Chroma16`](TxbSet::Chroma16)'s tables except `eob_pt`, which reads | 123 | /// [`Chroma16`](TxbSet::Chroma16)'s tables except `eob_pt`, which reads |
| @@ -1501,6 +1511,18 @@ impl Cdfs { | |||
| 1501 | tx_type: None, | 1511 | tx_type: None, |
| 1502 | eob_pt_class1: None, | 1512 | eob_pt_class1: None, |
| 1503 | }, | 1513 | }, |
| 1514 | + TxbSet::LumaRect32x8 => TxbTables { | ||
| 1515 | + side: 16, | ||
| 1516 | + txb_skip: &mut self.txb_skip_luma_16, | ||
| 1517 | + eob_pt: &mut self.eob_pt_256_luma, | ||
| 1518 | + eob_extra: &mut self.eob_extra_luma_16, | ||
| 1519 | + base: &mut self.base_luma_16, | ||
| 1520 | + base_eob: &mut self.base_eob_luma_16, | ||
| 1521 | + br: &mut self.br_luma_16, | ||
| 1522 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1523 | + tx_type: None, | ||
| 1524 | + eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), | ||
| 1525 | + }, | ||
| 1504 | TxbSet::LumaRect32x16 => TxbTables { | 1526 | TxbSet::LumaRect32x16 => TxbTables { |
| 1505 | side: 32, | 1527 | side: 32, |
| 1506 | txb_skip: &mut self.txb_skip_luma_32, | 1528 | txb_skip: &mut self.txb_skip_luma_32, |
crates/ec-av1/src/decode.rsmodified+402 -31
| @@ -1405,6 +1405,36 @@ pub(crate) fn sb_rect4_vert_hits() -> usize { | |||
| 1405 | SB_RECT4_VERT_HITS.with(|c| c.get()) | 1405 | SB_RECT4_VERT_HITS.with(|c| c.get()) |
| 1406 | } | 1406 | } |
| 1407 | 1407 | ||
| 1408 | +// lane-tx64x16 r3: the 32x32-level 1:4 arms, counted per orientation -- | ||
| 1409 | +// `PARTITION_HORZ_4` (four 32x8 strips) and `PARTITION_VERT_4` (four 8x32 | ||
| 1410 | +// strips), the arms the ReelB mid-film extract stops at. | ||
| 1411 | +thread_local! { | ||
| 1412 | + static RECT4_32_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1413 | + static RECT4_32_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1414 | +} | ||
| 1415 | + | ||
| 1416 | +/// How many 32x32-level 1:4 strips actually read coefficients (non-skip): | ||
| 1417 | +/// a gate that only counted strips would pass on an all-skip stream, which | ||
| 1418 | +/// exercises none of the new scan/context tables. | ||
| 1419 | +thread_local! { | ||
| 1420 | + static RECT4_COEFF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1421 | +} | ||
| 1422 | + | ||
| 1423 | +/// Current value of `RECT4_COEFF_HITS`. | ||
| 1424 | +pub(crate) fn rect4_coeff_hits() -> usize { | ||
| 1425 | + RECT4_COEFF_HITS.with(|c| c.get()) | ||
| 1426 | +} | ||
| 1427 | + | ||
| 1428 | +/// Current value of `RECT4_32_HORZ_HITS` (32x8 strips decoded). | ||
| 1429 | +pub(crate) fn rect4_32_horz_hits() -> usize { | ||
| 1430 | + RECT4_32_HORZ_HITS.with(|c| c.get()) | ||
| 1431 | +} | ||
| 1432 | + | ||
| 1433 | +/// Current value of `RECT4_32_VERT_HITS` (8x32 strips decoded). | ||
| 1434 | +pub(crate) fn rect4_32_vert_hits() -> usize { | ||
| 1435 | + RECT4_32_VERT_HITS.with(|c| c.get()) | ||
| 1436 | +} | ||
| 1437 | + | ||
| 1408 | // lane-rect64q r1: how many of [`decode_block_rect64`]'s three per-plane | 1438 | // lane-rect64q r1: how many of [`decode_block_rect64`]'s three per-plane |
| 1409 | // dequant calls actually observed `CURRENT_Q_IDX != base_q_idx` -- proof the | 1439 | // dequant calls actually observed `CURRENT_Q_IDX != base_q_idx` -- proof the |
| 1410 | // running-vs-stale-snapshot bug this round fixed is exercised by a gate, not | 1440 | // running-vs-stale-snapshot bug this round fixed is exercised by a gate, not |
| @@ -1979,6 +2009,27 @@ const SCAN_8X32: [u16; 256] = [ | |||
| 1979 | 239, 246, 253, 247, 254, 255, | 2009 | 239, 246, 253, 247, 254, 255, |
| 1980 | ]; | 2010 | ]; |
| 1981 | 2011 | ||
| 2012 | +/// `Default_Scan_16x4`, this decoder's own row-major transcription of | ||
| 2013 | +/// libaom's column-major `default_scan_16x4` (`scan.c:66`) -- the CHROMA | ||
| 2014 | +/// plane of a 32x8 `PARTITION_HORZ_4` strip at the 32x32 level | ||
| 2015 | +/// (lane-tx64x16 r3). The transcription rule (`row * w + col` with | ||
| 2016 | +/// `row = p % h`, `col = p / h`) was validated by REGENERATING the existing | ||
| 2017 | +/// [`SCAN_16X8`] from `default_scan_16x8` byte for byte before these two | ||
| 2018 | +/// were emitted -- a naive copy installs the transpose (class | ||
| 2019 | +/// reference-layout-not-spec). | ||
| 2020 | +const SCAN_16X4: [u16; 64] = [ | ||
| 2021 | + 0, 16, 1, 32, 17, 2, 48, 33, 18, 3, 49, 34, 19, 4, 50, 35, 20, 5, 51, 36, 21, 6, 52, 37, 22, 7, | ||
| 2022 | + 53, 38, 23, 8, 54, 39, 24, 9, 55, 40, 25, 10, 56, 41, 26, 11, 57, 42, 27, 12, 58, 43, 28, 13, | ||
| 2023 | + 59, 44, 29, 14, 60, 45, 30, 15, 61, 46, 31, 62, 47, 63, | ||
| 2024 | +]; | ||
| 2025 | +/// `Default_Scan_4x16`, [`SCAN_16X4`]'s transpose (the chroma plane of an | ||
| 2026 | +/// 8x32 `PARTITION_VERT_4` strip). | ||
| 2027 | +const SCAN_4X16: [u16; 64] = [ | ||
| 2028 | + 0, 1, 4, 2, 5, 8, 3, 6, 9, 12, 7, 10, 13, 16, 11, 14, 17, 20, 15, 18, 21, 24, 19, 22, 25, 28, | ||
| 2029 | + 23, 26, 29, 32, 27, 30, 33, 36, 31, 34, 37, 40, 35, 38, 41, 44, 39, 42, 45, 48, 43, 46, 49, 52, | ||
| 2030 | + 47, 50, 53, 56, 51, 54, 57, 60, 55, 58, 61, 59, 62, 63, | ||
| 2031 | +]; | ||
| 2032 | + | ||
| 1982 | /// [`neighbour`] with independent `w` (row stride)/`h` (row-bound) extents | 2033 | /// [`neighbour`] with independent `w` (row stride)/`h` (row-bound) extents |
| 1983 | /// (lane-rectwire, mirrors [`record_rect`](Neighbours::record_rect)'s | 2034 | /// (lane-rectwire, mirrors [`record_rect`](Neighbours::record_rect)'s |
| 1984 | /// asymmetric-extent pattern). | 2035 | /// asymmetric-extent pattern). |
| @@ -4817,6 +4868,280 @@ fn decode_leaf_rect( | |||
| 4817 | Ok(mode) | 4868 | Ok(mode) |
| 4818 | } | 4869 | } |
| 4819 | 4870 | ||
| 4871 | +/// Decodes one 32x8 / 8x32 strip of a 32x32-level `PARTITION_HORZ_4` / | ||
| 4872 | +/// `PARTITION_VERT_4` (lane-tx64x16 r3): [`decode_block_rect`]'s 4:1 sibling, | ||
| 4873 | +/// addressed by REAL mi coordinates for the same reason [`decode_leaf_rect`] | ||
| 4874 | +/// is -- strips 1 and 3 start 8 px into a 16-px [`SUB`] cell, which an | ||
| 4875 | +/// `at`-derived `px = c * SUB` cannot name. `prev_strip` carries the previous | ||
| 4876 | +/// strip's mode so this one's mode context sees its true above/left | ||
| 4877 | +/// neighbour inside the same 32x32 (`decode_leaf_rect`'s convention). | ||
| 4878 | +/// | ||
| 4879 | +/// Tables: LUMA `TX_32X8`/`TX_8X32` averages to the 16x16 entropy context | ||
| 4880 | +/// ([`TxbSet::LumaRect32x8`], 256 positions) and scans with | ||
| 4881 | +/// [`SCAN_32X8`]/[`SCAN_8X32`]; CHROMA `TX_16X4`/`TX_4X16` averages to the | ||
| 4882 | +/// 8x8 one ([`TxbSet::Chroma8`], 64 positions) and scans with | ||
| 4883 | +/// [`SCAN_16X4`]/[`SCAN_4X16`]. Neither shape takes the rect sqrt2 scale -- | ||
| 4884 | +/// `get_rect_tx_log_ratio` fires at ratio 1 only, and this is ratio 2 | ||
| 4885 | +/// (`inverse_transform_2d_typed_wh`'s own `rect_scale`). | ||
| 4886 | +/// | ||
| 4887 | +/// A split transform (`tx_depth != 0`) refuses by name: `depth_to_tx_size` of | ||
| 4888 | +/// a 4:1 strip is not simply `bw.min(bh) >> (depth - 1)` the way a 2:1 | ||
| 4889 | +/// strip's is, so [`decode_rect_split`]'s per-unit walk cannot be reused | ||
| 4890 | +/// unexamined. | ||
| 4891 | +#[allow(clippy::too_many_arguments)] | ||
| 4892 | +fn decode_block_rect4( | ||
| 4893 | + dec: &mut SymbolDecoder, | ||
| 4894 | + cdfs: &mut Cdfs, | ||
| 4895 | + neighbours: &mut Neighbours, | ||
| 4896 | + strip_mi: (usize, usize), | ||
| 4897 | + bw: usize, | ||
| 4898 | + bh: usize, | ||
| 4899 | + prev_strip: Option<((usize, usize), usize)>, | ||
| 4900 | + y: &mut PlaneBuf, | ||
| 4901 | + u: &mut PlaneBuf, | ||
| 4902 | + v: &mut PlaneBuf, | ||
| 4903 | + enable_filter_intra: bool, | ||
| 4904 | + allow_screen_content_tools: bool, | ||
| 4905 | + base_q_idx: u8, | ||
| 4906 | + tx_select: bool, | ||
| 4907 | +) -> Result<(usize, usize)> { | ||
| 4908 | + let _ = base_q_idx; | ||
| 4909 | + let (mi_r, mi_c) = strip_mi; | ||
| 4910 | + let (r, c) = (mi_r / (SUB / MI), mi_c / (SUB / MI)); | ||
| 4911 | + let (mi_w, mi_h) = (bw / MI, bh / MI); | ||
| 4912 | + let mut above_mode = neighbours.above_mode[c]; | ||
| 4913 | + let mut left_mode = neighbours.left_mode[r]; | ||
| 4914 | + if let Some(((pr, pc), pmode)) = prev_strip { | ||
| 4915 | + if pc == mi_c && mi_r == pr + mi_h { | ||
| 4916 | + above_mode = pmode; | ||
| 4917 | + } else if pr == mi_r && mi_c == pc + mi_w { | ||
| 4918 | + left_mode = pmode; | ||
| 4919 | + } | ||
| 4920 | + } | ||
| 4921 | + let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) = | ||
| 4922 | + read_intra_mode_rect( | ||
| 4923 | + dec, | ||
| 4924 | + cdfs, | ||
| 4925 | + above_mode, | ||
| 4926 | + left_mode, | ||
| 4927 | + true, | ||
| 4928 | + bw, | ||
| 4929 | + bh, | ||
| 4930 | + enable_filter_intra, | ||
| 4931 | + neighbours.skip_txfm_ctx(mi_r, mi_c), | ||
| 4932 | + allow_screen_content_tools, | ||
| 4933 | + mi_r, | ||
| 4934 | + mi_c, | ||
| 4935 | + )?; | ||
| 4936 | + let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); | ||
| 4937 | + if smooth_neighbor { | ||
| 4938 | + SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); | ||
| 4939 | + } | ||
| 4940 | + let smooth_neighbor_uv = | ||
| 4941 | + is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]); | ||
| 4942 | + if filter_intra.is_some() { | ||
| 4943 | + FILTER_INTRA_RECT_HITS.with(|c| c.set(c.get() + 1)); | ||
| 4944 | + } | ||
| 4945 | + let uv_predict_mode = if uv_mode == UV_CFL_PRED { | ||
| 4946 | + DC_PRED | ||
| 4947 | + } else { | ||
| 4948 | + uv_mode | ||
| 4949 | + }; | ||
| 4950 | + let depth = if tx_select { | ||
| 4951 | + let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); | ||
| 4952 | + dec.symbol(&mut cdfs.tx_size_cat2[ctx]) | ||
| 4953 | + } else { | ||
| 4954 | + 0 | ||
| 4955 | + }; | ||
| 4956 | + if depth != 0 { | ||
| 4957 | + return Err(unsupported( | ||
| 4958 | + "a 32x32-level 1:4 strip with a split transform (per-unit 4:1 prediction is not \ | ||
| 4959 | + ported)", | ||
| 4960 | + )); | ||
| 4961 | + } | ||
| 4962 | + // The coarse (16-px [`SUB`] cell) mode/side arrays cannot name a strip | ||
| 4963 | + // that is 8 px tall, so each strip stamps every cell it touches and the | ||
| 4964 | + // LAST strip wins -- which is the right answer for the block below/right | ||
| 4965 | + // of the 32x32, the only reader outside it. Written after this strip's | ||
| 4966 | + // own context read above, never before. | ||
| 4967 | + for cell in 0..bw.div_ceil(SUB) { | ||
| 4968 | + neighbours.above_mode[c + cell] = mode; | ||
| 4969 | + neighbours.above_uv_mode[c + cell] = uv_predict_mode; | ||
| 4970 | + neighbours.above_side[c + cell] = bw; | ||
| 4971 | + } | ||
| 4972 | + for cell in 0..bh.div_ceil(SUB) { | ||
| 4973 | + neighbours.left_mode[r + cell] = mode; | ||
| 4974 | + neighbours.left_uv_mode[r + cell] = uv_predict_mode; | ||
| 4975 | + neighbours.left_side[r + cell] = bh; | ||
| 4976 | + } | ||
| 4977 | + let (px, py) = (mi_c * MI, mi_r * MI); | ||
| 4978 | + let (cpx, cpy) = (px / 2, py / 2); | ||
| 4979 | + let (chroma_w, chroma_h) = (bw / 2, bh / 2); | ||
| 4980 | + let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); | ||
| 4981 | + let (luma_scan, chroma_scan): (&[u16], &[u16]) = if bw > bh { | ||
| 4982 | + (&SCAN_32X8, &SCAN_16X4) | ||
| 4983 | + } else { | ||
| 4984 | + (&SCAN_8X32, &SCAN_4X16) | ||
| 4985 | + }; | ||
| 4986 | + let (luma_levels, u_levels, v_levels) = if skip { | ||
| 4987 | + ( | ||
| 4988 | + vec![0i32; bw * bh], | ||
| 4989 | + vec![0i32; chroma_w * chroma_h], | ||
| 4990 | + vec![0i32; chroma_w * chroma_h], | ||
| 4991 | + ) | ||
| 4992 | + } else { | ||
| 4993 | + let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); | ||
| 4994 | + let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x8, mode); | ||
| 4995 | + let (luma_levels, luma_tx_type) = read_coeffs_rect( | ||
| 4996 | + dec, | ||
| 4997 | + &mut luma_coding, | ||
| 4998 | + luma_scan, | ||
| 4999 | + bw, | ||
| 5000 | + bh, | ||
| 5001 | + 0, | ||
| 5002 | + dc_sign_ctx(around[0].2), | ||
| 5003 | + TxType::DctDct, | ||
| 5004 | + )?; | ||
| 5005 | + let mut planes = Vec::with_capacity(2); | ||
| 5006 | + for plane in 1..3 { | ||
| 5007 | + let default_tx = default_intra_tx_type(uv_predict_mode as u8); | ||
| 5008 | + let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1); | ||
| 5009 | + let mut coding = cdfs.txb(TxbSet::Chroma8, uv_predict_mode); | ||
| 5010 | + let (levels, tx_type) = read_coeffs_rect( | ||
| 5011 | + dec, | ||
| 5012 | + &mut coding, | ||
| 5013 | + chroma_scan, | ||
| 5014 | + chroma_w, | ||
| 5015 | + chroma_h, | ||
| 5016 | + skip_ctx, | ||
| 5017 | + dc_sign_ctx(around[plane].2), | ||
| 5018 | + default_tx, | ||
| 5019 | + )?; | ||
| 5020 | + planes.push((levels, tx_type)); | ||
| 5021 | + } | ||
| 5022 | + let (v_levels, v_tx_type) = planes.pop().expect("plane 2"); | ||
| 5023 | + let (u_levels, u_tx_type) = planes.pop().expect("plane 1"); | ||
| 5024 | + RECT4_COEFF_HITS.with(|c| c.set(c.get() + 1)); | ||
| 5025 | + let luma_residual = dequant_and_inverse_typed_wh( | ||
| 5026 | + &luma_levels, | ||
| 5027 | + bw, | ||
| 5028 | + bh, | ||
| 5029 | + crate::decode::bit_depth(), | ||
| 5030 | + block_q_idx(), | ||
| 5031 | + plane_q_delta(0).0, | ||
| 5032 | + plane_q_delta(0).1, | ||
| 5033 | + luma_tx_type, | ||
| 5034 | + ); | ||
| 5035 | + y.reconstruct_rect( | ||
| 5036 | + px, | ||
| 5037 | + py, | ||
| 5038 | + bw, | ||
| 5039 | + bh, | ||
| 5040 | + mode, | ||
| 5041 | + angle_delta_y, | ||
| 5042 | + reach, | ||
| 5043 | + &luma_residual, | ||
| 5044 | + None, | ||
| 5045 | + filter_intra, | ||
| 5046 | + smooth_neighbor, | ||
| 5047 | + ); | ||
| 5048 | + let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); | ||
| 5049 | + for (plane, buf, levels, tx_type) in [ | ||
| 5050 | + (1usize, &mut *u, &u_levels, u_tx_type), | ||
| 5051 | + (2, &mut *v, &v_levels, v_tx_type), | ||
| 5052 | + ] { | ||
| 5053 | + let residual = dequant_and_inverse_typed_wh( | ||
| 5054 | + levels, | ||
| 5055 | + chroma_w, | ||
| 5056 | + chroma_h, | ||
| 5057 | + crate::decode::bit_depth(), | ||
| 5058 | + block_q_idx(), | ||
| 5059 | + plane_q_delta(plane).0, | ||
| 5060 | + plane_q_delta(plane).1, | ||
| 5061 | + tx_type, | ||
| 5062 | + ); | ||
| 5063 | + buf.reconstruct_rect( | ||
| 5064 | + cpx, | ||
| 5065 | + cpy, | ||
| 5066 | + chroma_w, | ||
| 5067 | + chroma_h, | ||
| 5068 | + uv_predict_mode, | ||
| 5069 | + angle_delta_uv, | ||
| 5070 | + reach, | ||
| 5071 | + &residual, | ||
| 5072 | + alpha | ||
| 5073 | + .zip(ac.as_deref()) | ||
| 5074 | + .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), | ||
| 5075 | + None, | ||
| 5076 | + smooth_neighbor_uv, | ||
| 5077 | + ); | ||
| 5078 | + } | ||
| 5079 | + neighbours.record_mi_rect( | ||
| 5080 | + (mi_r, mi_c), | ||
| 5081 | + bw, | ||
| 5082 | + bh, | ||
| 5083 | + &[luma_levels, u_levels, v_levels], | ||
| 5084 | + ); | ||
| 5085 | + neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip); | ||
| 5086 | + neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0); | ||
| 5087 | + if bw > bh { | ||
| 5088 | + RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1)); | ||
| 5089 | + } else { | ||
| 5090 | + RECT4_32_VERT_HITS.with(|c| c.set(c.get() + 1)); | ||
| 5091 | + } | ||
| 5092 | + return Ok((mode, uv_predict_mode)); | ||
| 5093 | + }; | ||
| 5094 | + y.reconstruct_rect( | ||
| 5095 | + px, | ||
| 5096 | + py, | ||
| 5097 | + bw, | ||
| 5098 | + bh, | ||
| 5099 | + mode, | ||
| 5100 | + angle_delta_y, | ||
| 5101 | + reach, | ||
| 5102 | + &luma_levels, | ||
| 5103 | + None, | ||
| 5104 | + filter_intra, | ||
| 5105 | + smooth_neighbor, | ||
| 5106 | + ); | ||
| 5107 | + let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); | ||
| 5108 | + u.reconstruct_rect( | ||
| 5109 | + cpx, | ||
| 5110 | + cpy, | ||
| 5111 | + chroma_w, | ||
| 5112 | + chroma_h, | ||
| 5113 | + uv_predict_mode, | ||
| 5114 | + angle_delta_uv, | ||
| 5115 | + reach, | ||
| 5116 | + &u_levels, | ||
| 5117 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | ||
| 5118 | + None, | ||
| 5119 | + smooth_neighbor_uv, | ||
| 5120 | + ); | ||
| 5121 | + v.reconstruct_rect( | ||
| 5122 | + cpx, | ||
| 5123 | + cpy, | ||
| 5124 | + chroma_w, | ||
| 5125 | + chroma_h, | ||
| 5126 | + uv_predict_mode, | ||
| 5127 | + angle_delta_uv, | ||
| 5128 | + reach, | ||
| 5129 | + &v_levels, | ||
| 5130 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | ||
| 5131 | + None, | ||
| 5132 | + smooth_neighbor_uv, | ||
| 5133 | + ); | ||
| 5134 | + neighbours.record_mi_rect((mi_r, mi_c), bw, bh, &[luma_levels, u_levels, v_levels]); | ||
| 5135 | + neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip); | ||
| 5136 | + neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0); | ||
| 5137 | + if bw > bh { | ||
| 5138 | + RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1)); | ||
| 5139 | + } else { | ||
| 5140 | + RECT4_32_VERT_HITS.with(|c| c.set(c.get() + 1)); | ||
| 5141 | + } | ||
| 5142 | + Ok((mode, uv_predict_mode)) | ||
| 5143 | +} | ||
| 5144 | + | ||
| 4820 | /// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/ | 5145 | /// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/ |
| 4821 | /// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` / | 5146 | /// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` / |
| 4822 | /// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike | 5147 | /// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike |
| @@ -9411,6 +9736,47 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 9411 | reduced_tx_set, | 9736 | reduced_tx_set, |
| 9412 | )?; | 9737 | )?; |
| 9413 | } | 9738 | } |
| 9739 | + PARTITION_HORZ_4 | PARTITION_VERT_4 => { | ||
| 9740 | + // lane-tx64x16 r3: the 1:4 pair at the 32x32 | ||
| 9741 | + // level -- four 32x8 (or 8x32) strips in | ||
| 9742 | + // raster order, `quarter_step` = 2 mi, with | ||
| 9743 | + // libaom `decode_partition`'s own `i > 0` | ||
| 9744 | + // frame-edge break. | ||
| 9745 | + let horz = part32 == PARTITION_HORZ_4; | ||
| 9746 | + let base_mi = (at32.0 * (SUB / MI), at32.1 * (SUB / MI)); | ||
| 9747 | + let mut prev: Option<((usize, usize), usize)> = None; | ||
| 9748 | + for i in 0..4 { | ||
| 9749 | + let strip_mi = if horz { | ||
| 9750 | + (base_mi.0 + i * 2, base_mi.1) | ||
| 9751 | + } else { | ||
| 9752 | + (base_mi.0, base_mi.1 + i * 2) | ||
| 9753 | + }; | ||
| 9754 | + if i > 0 | ||
| 9755 | + && (strip_mi.0 >= mi_rows as usize | ||
| 9756 | + || strip_mi.1 >= mi_cols as usize) | ||
| 9757 | + { | ||
| 9758 | + break; | ||
| 9759 | + } | ||
| 9760 | + let (bw, bh) = if horz { (32, 8) } else { (8, 32) }; | ||
| 9761 | + let (mode, _uv) = decode_block_rect4( | ||
| 9762 | + &mut dec, | ||
| 9763 | + &mut cdfs, | ||
| 9764 | + &mut neighbours, | ||
| 9765 | + strip_mi, | ||
| 9766 | + bw, | ||
| 9767 | + bh, | ||
| 9768 | + prev, | ||
| 9769 | + &mut y, | ||
| 9770 | + &mut u, | ||
| 9771 | + &mut v, | ||
| 9772 | + enable_filter_intra, | ||
| 9773 | + allow_screen_content_tools, | ||
| 9774 | + base_q_idx, | ||
| 9775 | + tx_select, | ||
| 9776 | + )?; | ||
| 9777 | + prev = Some((strip_mi, mode)); | ||
| 9778 | + } | ||
| 9779 | + } | ||
| 9414 | _ => { | 9780 | _ => { |
| 9415 | return Err(unsupported(format!( | 9781 | return Err(unsupported(format!( |
| 9416 | "a 32x32 partition type this decoder does not code (value={part32})" | 9782 | "a 32x32 partition type this decoder does not code (value={part32})" |
| @@ -16470,38 +16836,33 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 16470 | mod tests { | 16836 | mod tests { |
| 16471 | use super::*; | 16837 | use super::*; |
| 16472 | 16838 | ||
| 16473 | - /// libaom's generating rule (`txb_common.h:199-209`) in DISPLAY | 16839 | + /// lane-tx64x16 r3: the two new 4:1 chroma scans are a TRANSPOSED PAIR -- |
| 16474 | - /// coordinates, pinned against the two rect transcriptions in [`cdf`]. | 16840 | + /// `SCAN_4X16[i]` must name the transpose of the position |
| 16475 | - /// lane-tx64x16 r2: this test read the tables `[col][row]` (lane-rectsplit | 16841 | + /// `SCAN_16X4[i]` names (class scan-weights-cross-axis: a naive copy of |
| 16476 | - /// r2's column-major premise) while r3 reverted the tables themselves to | 16842 | + /// libaom's column-major `default_scan_*` installs the transpose and only |
| 16477 | - /// display-major `[row][col]` -- the order [`base_ctx`] itself reads them | 16843 | + /// an asymmetric check catches it). Also pins both as permutations, and |
| 16478 | - /// at `decode.rs`'s `TxClass::TwoD` arm, and the order every merged rect | 16844 | + /// pins the same relation for the 32x8/8x32 luma pair this arm reuses. |
| 16479 | - /// gate is green under. The test was left pinning the abandoned half, so | ||
| 16480 | - /// it failed on `main` (32x64 display (row 0, col 2): table says 6 read | ||
| 16481 | - /// transposed, the rule says 11). Read in the consumer's order. | ||
| 16482 | #[test] | 16845 | #[test] |
| 16483 | - fn nz_map_ctx_offset_tables_match_the_rect_rule() { | 16846 | + fn the_rect4_scans_are_transposed_pairs() { |
| 16484 | - for (w, h, table) in [ | 16847 | + for (a, b, w, h) in [ |
| 16485 | - (32usize, 64usize, &cdf::NZ_MAP_CTX_OFFSET_32X64), | 16848 | + (&SCAN_16X4[..], &SCAN_4X16[..], 16usize, 4usize), |
| 16486 | - (64, 32, &cdf::NZ_MAP_CTX_OFFSET_64X32), | 16849 | + (&SCAN_32X8[..], &SCAN_8X32[..], 32, 8), |
| 16487 | ] { | 16850 | ] { |
| 16488 | - for row in 0..5usize { | 16851 | + let mut seen_a: Vec<u16> = a.to_vec(); |
| 16489 | - for col in 0..5usize { | 16852 | + seen_a.sort_unstable(); |
| 16490 | - let want = if row == 0 && col == 0 { | 16853 | + assert_eq!( |
| 16491 | - 0 | 16854 | + seen_a, |
| 16492 | - } else if w < h && row < 2 { | 16855 | + (0..(w * h) as u16).collect::<Vec<_>>(), |
| 16493 | - 11 | 16856 | + "{w}x{h} scan is not a permutation of its positions" |
| 16494 | - } else if w > h && col < 2 { | 16857 | + ); |
| 16495 | - 16 | 16858 | + for (i, (&pa, &pb)) in a.iter().zip(b.iter()).enumerate() { |
| 16496 | - } else { | 16859 | + let (row, col) = (pa as usize / w, pa as usize % w); |
| 16497 | - cdf::NZ_MAP_CTX_OFFSET_32[row][col] | 16860 | + assert_eq!( |
| 16498 | - }; | 16861 | + pb as usize, |
| 16499 | - assert_eq!( | 16862 | + col * w.min(h) + row, |
| 16500 | - table[row][col], | 16863 | + "scan step {i}: {w}x{h} visits (row {row}, col {col}) but its transpose \ |
| 16501 | - want, | 16864 | + visits position {pb}" |
| 16502 | - "{w}x{h} nz_map offset at display (row {row}, col {col})" | 16865 | + ); |
| 16503 | - ); | ||
| 16504 | - } | ||
| 16505 | } | 16866 | } |
| 16506 | } | 16867 | } |
| 16507 | } | 16868 | } |
| @@ -16528,10 +16889,20 @@ mod tests { | |||
| 16528 | // An all-zero neighbourhood makes the magnitude term 0, | 16889 | // An all-zero neighbourhood makes the magnitude term 0, |
| 16529 | // so `base_ctx` returns the offset itself. | 16890 | // so `base_ctx` returns the offset itself. |
| 16530 | let got = base_ctx(&grid, 32, row, col, TxClass::TwoD, shape); | 16891 | let got = base_ctx(&grid, 32, row, col, TxClass::TwoD, shape); |
| 16892 | + // lane-tx64x16 r3, on cherry-picking this test onto main: | ||
| 16893 | + // `main`'s two rect transcriptions in [`cdf`] are the | ||
| 16894 | + // TRANSPOSE of lane-rectsplit's (main's | ||
| 16895 | + // `NZ_MAP_CTX_OFFSET_64X32` row 0 is `[0, 16, 6, 6, 21]`, | ||
| 16896 | + // rectsplit's is `[0, 16, 16, 16, 16]`), so the same rule | ||
| 16897 | + // is pinned here as `[row][col]`. The consumer reads | ||
| 16898 | + // NEITHER -- `base_ctx` states libaom's generating rule | ||
| 16899 | + // directly -- so the layouts are equivalent for decoding; | ||
| 16900 | + // whoever merges both branches must keep table layout and | ||
| 16901 | + // this index in step. | ||
| 16531 | let want = if row == 0 && col == 0 { | 16902 | let want = if row == 0 && col == 0 { |
| 16532 | 0 | 16903 | 0 |
| 16533 | } else { | 16904 | } else { |
| 16534 | - table[col][row] as usize | 16905 | + table[row][col] as usize |
| 16535 | }; | 16906 | }; |
| 16536 | assert_eq!(got, want, "{shape:?} at (row {row}, col {col})"); | 16907 | assert_eq!(got, want, "{shape:?} at (row {row}, col {col})"); |
| 16537 | } | 16908 | } |
crates/ec-av1/src/encode.rsmodified+29 -4
| @@ -1100,9 +1100,22 @@ impl Drop for VertAbGuard { | |||
| 1100 | /// r1: the two rect strips PARTITION_HORZ/VERT ever produce at the 32x32 | 1100 | /// r1: the two rect strips PARTITION_HORZ/VERT ever produce at the 32x32 |
| 1101 | /// level, transcribed verbatim (not derived): `[0]` is 32-wide, `[1]` is | 1101 | /// level, transcribed verbatim (not derived): `[0]` is 32-wide, `[1]` is |
| 1102 | /// 16-wide. | 1102 | /// 16-wide. |
| 1103 | -const HAS_TOP_RIGHT_RECT: [&[u8]; 2] = [&[15, 5, 7, 5], &[255, 119, 127, 119]]; | 1103 | +const HAS_TOP_RIGHT_RECT: [&[u8]; 4] = [ |
| 1104 | + &[15, 5, 7, 5], | ||
| 1105 | + &[255, 119, 127, 119], | ||
| 1106 | + // lane-tx64x16 r3: `has_tr_32x8` / `has_tr_8x32` (`reconintra.c:122-127`), | ||
| 1107 | + // the 4:1 strips of a 32x32-level `PARTITION_HORZ_4`/`VERT_4`. | ||
| 1108 | + &[15, 0, 5, 0, 7, 0, 5, 0], | ||
| 1109 | + &[255, 255, 127, 127, 255, 127, 127, 127], | ||
| 1110 | +]; | ||
| 1104 | /// `has_bl_32x16`/`has_bl_16x32`, same source, same order. | 1111 | /// `has_bl_32x16`/`has_bl_16x32`, same source, same order. |
| 1105 | -const HAS_BOTTOM_LEFT_RECT: [&[u8]; 2] = [&[78, 14, 78, 14], &[16, 0, 16, 0]]; | 1112 | +const HAS_BOTTOM_LEFT_RECT: [&[u8]; 4] = [ |
| 1113 | + &[78, 14, 78, 14], | ||
| 1114 | + &[16, 0, 16, 0], | ||
| 1115 | + // `has_bl_32x8` / `has_bl_8x32` (`reconintra.c:305-310`). | ||
| 1116 | + &[238, 78, 238, 14, 238, 78, 238, 14], | ||
| 1117 | + &[0, 1, 0, 0, 0, 1, 0, 0], | ||
| 1118 | +]; | ||
| 1106 | 1119 | ||
| 1107 | impl Reach { | 1120 | impl Reach { |
| 1108 | /// What a block of `side` samples at `(x, y)` may read past its own edges, | 1121 | /// What a block of `side` samples at `(x, y)` may read past its own edges, |
| @@ -1150,7 +1163,7 @@ impl Reach { | |||
| 1150 | if col + 1 == per_col { | 1163 | if col + 1 == per_col { |
| 1151 | return false; | 1164 | return false; |
| 1152 | } | 1165 | } |
| 1153 | - let table = HAS_TOP_RIGHT_RECT[usize::from(bw == 16)]; | 1166 | + let table = HAS_TOP_RIGHT_RECT[Self::rect_table(bw, bh)]; |
| 1154 | Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8)) | 1167 | Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8)) |
| 1155 | } | 1168 | } |
| 1156 | 1169 | ||
| @@ -1162,7 +1175,7 @@ impl Reach { | |||
| 1162 | if row + 1 == per_row { | 1175 | if row + 1 == per_row { |
| 1163 | return false; | 1176 | return false; |
| 1164 | } | 1177 | } |
| 1165 | - let table = HAS_BOTTOM_LEFT_RECT[usize::from(bw == 16)]; | 1178 | + let table = HAS_BOTTOM_LEFT_RECT[Self::rect_table(bw, bh)]; |
| 1166 | Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8)) | 1179 | Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8)) |
| 1167 | } | 1180 | } |
| 1168 | 1181 | ||
| @@ -1260,6 +1273,18 @@ impl Reach { | |||
| 1260 | /// superblock -- using `per_side` (`SUPERBLOCK` / `side`, 64-relative) | 1273 | /// superblock -- using `per_side` (`SUPERBLOCK` / `side`, 64-relative) |
| 1261 | /// here instead indexes the wrong bit for every block size but the one | 1274 | /// here instead indexes the wrong bit for every block size but the one |
| 1262 | /// where 64 and 128 give the same stride. | 1275 | /// where 64 and 128 give the same stride. |
| 1276 | + /// Which row of [`HAS_TOP_RIGHT_RECT`]/[`HAS_BOTTOM_LEFT_RECT`] a | ||
| 1277 | + /// rectangular block reads. The 2:1 pair keeps its historical | ||
| 1278 | + /// `bw == 16` selector; the 4:1 pair (lane-tx64x16 r3) is named | ||
| 1279 | + /// explicitly, so no existing shape changes row. | ||
| 1280 | + fn rect_table(bw: usize, bh: usize) -> usize { | ||
| 1281 | + match (bw, bh) { | ||
| 1282 | + (32, 8) => 2, | ||
| 1283 | + (8, 32) => 3, | ||
| 1284 | + _ => usize::from(bw == 16), | ||
| 1285 | + } | ||
| 1286 | + } | ||
| 1287 | + | ||
| 1263 | fn table_stride(side: usize) -> usize { | 1288 | fn table_stride(side: usize) -> usize { |
| 1264 | 128 / side | 1289 | 128 / side |
| 1265 | } | 1290 | } |
crates/ec-av1/src/refusal_inventory.rsmodified+1 -0
| @@ -43,6 +43,7 @@ const REFUSALS: &[&str] = &[ | |||
| 43 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", | 43 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| 44 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", | 44 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| 45 | "a 32x32 partition type this decoder does not code (value={part32})", | 45 | "a 32x32 partition type this decoder does not code (value={part32})", |
| 46 | + "a 32x32-level 1:4 strip with a split transform (per-unit 4:1 prediction is not ported)", | ||
| 46 | "a Golomb tail longer than this decoder reads", | 47 | "a Golomb tail longer than this decoder reads", |
| 47 | "a tx_type symbol outside its CDF's own set: {t}", | 48 | "a tx_type symbol outside its CDF's own set: {t}", |
| 48 | "an INTER 32x32 partition type this decoder does not code (value={part32})", | 49 | "an INTER 32x32 partition type this decoder does not code (value={part32})", |
crates/ec-av1/src/stream.rsmodified+235 -0
| @@ -13132,4 +13132,239 @@ mod tests { | |||
| 13132 | mismatched -- other lanes' shapes)" | 13132 | mismatched -- other lanes' shapes)" |
| 13133 | ); | 13133 | ); |
| 13134 | } | 13134 | } |
| 13135 | + | ||
| 13136 | + /// lane-tx64x16 r3: the 32x32-LEVEL 1:4 pair -- `PARTITION_HORZ_4` / | ||
| 13137 | + /// `PARTITION_VERT_4` at 32x32, i.e. four 32x8 / 8x32 strips, the arm the | ||
| 13138 | + /// ReelB mid-film extract stops at ("a 32x32 partition type this | ||
| 13139 | + /// decoder does not code (value=8)"). `--min-partition-size=8` is what | ||
| 13140 | + /// lets aomenc's RD reach the 32-level 1:4 shapes; `--max-partition-size=32` | ||
| 13141 | + /// keeps the superblock-level pair (already gated by its own test above) | ||
| 13142 | + /// out of the counters. Both orientations HARD-asserted per bit depth -- | ||
| 13143 | + /// the luma scans and the two new chroma scans (`SCAN_16X4`/`SCAN_4X16`) | ||
| 13144 | + /// are transposed pairs, so a one-sided gate cannot catch a transposition | ||
| 13145 | + /// (class scan-weights-cross-axis). `rect4_coeff_hits` is asserted too: | ||
| 13146 | + /// an all-skip stream would exercise none of the new coefficient tables | ||
| 13147 | + /// (class gate-blind-to-feature). Only hits earned inside an attempt that | ||
| 13148 | + /// then compared pixel-exact are counted (class | ||
| 13149 | + /// gate-skips-on-its-own-failure); the 10-bit arm is what retires | ||
| 13150 | + /// `enable-1to4-partitions` from `NEVER_EXERCISED_10BIT`. | ||
| 13151 | + #[test] | ||
| 13152 | + // lane-tx64x16 r3, MEASURED, not a hunch: no recipe tried this round makes | ||
| 13153 | + // aomenc's RD emit a 32x32-level 1:4 partition on synthetic fixtures -- | ||
| 13154 | + // 20/20 attempts of the recipe below (min-partition-size=8, | ||
| 13155 | + // max-partition-size=32) carried ZERO 32-level 1:4 blocks, as did a | ||
| 13156 | + // vertically-squeezed variant and a horizontally-blurred one (the latter | ||
| 13157 | + // additionally tripped the screen-content refusal). The wiring IS | ||
| 13158 | + // exercised by real content -- see this round's report for the film probe | ||
| 13159 | + // -- but until a fixture recipe is found this gate can prove nothing, and | ||
| 13160 | + // a gate that passes by never seeing its feature is worse than an ignored | ||
| 13161 | + // one (class gate-blind-to-feature). Un-ignore with the recipe, never with | ||
| 13162 | + // a weakened assert. | ||
| 13163 | + #[ignore = "no fixture recipe yet emits a 32-level 1:4 partition (lanes/tx64x16-r3.report.md)"] | ||
| 13164 | + fn a_real_aomenc_stream_with_a_32x32_level_1to4_partition_decodes_pixel_exact() { | ||
| 13165 | + const NAME: &str = | ||
| 13166 | + "a_real_aomenc_stream_with_a_32x32_level_1to4_partition_decodes_pixel_exact"; | ||
| 13167 | + let _gate_lock = lock_gate_counters(); | ||
| 13168 | + if !have_ffmpeg() { | ||
| 13169 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 13170 | + return; | ||
| 13171 | + } | ||
| 13172 | + if !have_aomenc() { | ||
| 13173 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 13174 | + return; | ||
| 13175 | + } | ||
| 13176 | + let (width, height, frame_count) = (192usize, 128usize, 1usize); | ||
| 13177 | + let n_attempts: u32 = std::env::var("EC_TX64X16_GATE32_ATTEMPTS") | ||
| 13178 | + .ok() | ||
| 13179 | + .and_then(|s| s.parse().ok()) | ||
| 13180 | + .unwrap_or(20); | ||
| 13181 | + for bit_depth in [8u32, 10u32] { | ||
| 13182 | + let mut named_refusals = 0u32; | ||
| 13183 | + let mut matched = 0u32; | ||
| 13184 | + let (mut horz_proved, mut vert_proved, mut coeff_proved) = (0usize, 0usize, 0usize); | ||
| 13185 | + let (mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32); | ||
| 13186 | + for attempt in 0..n_attempts { | ||
| 13187 | + let seed = 42 + attempt; | ||
| 13188 | + let duration = frame_count as f64 / 25.0; | ||
| 13189 | + // Odd attempts render the SAME generator rotated 90 degrees, | ||
| 13190 | + // the transposed-pair discipline the superblock-level 1:4 | ||
| 13191 | + // gate above documents. | ||
| 13192 | + let source = if attempt % 2 == 0 { | ||
| 13193 | + gradients_source(seed, width, height, &format!("duration={duration}:rate=25")) | ||
| 13194 | + } else { | ||
| 13195 | + format!( | ||
| 13196 | + "{},transpose=1", | ||
| 13197 | + gradients_source( | ||
| 13198 | + seed, | ||
| 13199 | + height, | ||
| 13200 | + width, | ||
| 13201 | + &format!("duration={duration}:rate=25") | ||
| 13202 | + ) | ||
| 13203 | + ) | ||
| 13204 | + }; | ||
| 13205 | + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 13206 | + let y4m = Command::new("ffmpeg") | ||
| 13207 | + .args([ | ||
| 13208 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), | ||
| 13209 | + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | ||
| 13210 | + ]) | ||
| 13211 | + .stdin(Stdio::null()) | ||
| 13212 | + .stdout(Stdio::piped()) | ||
| 13213 | + .stderr(Stdio::piped()) | ||
| 13214 | + .output() | ||
| 13215 | + .expect("ffmpeg failed to run"); | ||
| 13216 | + assert!( | ||
| 13217 | + y4m.status.success(), | ||
| 13218 | + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", | ||
| 13219 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 13220 | + ); | ||
| 13221 | + let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 13222 | + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 13223 | + let args: Vec<&str> = vec![ | ||
| 13224 | + "--codec=av1", | ||
| 13225 | + "--passes=1", | ||
| 13226 | + "--end-usage=q", | ||
| 13227 | + "--cq-level=45", | ||
| 13228 | + "--cpu-used=0", | ||
| 13229 | + "--threads=1", | ||
| 13230 | + "--row-mt=0", | ||
| 13231 | + "--sb-size=64", | ||
| 13232 | + &depth_arg, | ||
| 13233 | + &input_depth_arg, | ||
| 13234 | + "--enable-rect-partitions=1", | ||
| 13235 | + "--enable-ab-partitions=0", | ||
| 13236 | + "--enable-1to4-partitions=1", | ||
| 13237 | + "--min-partition-size=8", | ||
| 13238 | + "--max-partition-size=32", | ||
| 13239 | + "--enable-restoration=0", | ||
| 13240 | + "--enable-palette=0", | ||
| 13241 | + "--deltaq-mode=0", | ||
| 13242 | + "--enable-filter-intra=0", | ||
| 13243 | + "--enable-cfl-intra=0", | ||
| 13244 | + "--enable-intrabc=0", | ||
| 13245 | + "--enable-tx-size-search=0", | ||
| 13246 | + "--obu", | ||
| 13247 | + "-o", | ||
| 13248 | + "-", | ||
| 13249 | + "-", | ||
| 13250 | + ]; | ||
| 13251 | + let mut child = Command::new(aomenc_path()) | ||
| 13252 | + .args(&args) | ||
| 13253 | + .stdin(Stdio::piped()) | ||
| 13254 | + .stdout(Stdio::piped()) | ||
| 13255 | + .stderr(Stdio::piped()) | ||
| 13256 | + .spawn() | ||
| 13257 | + .expect("aomenc failed to start"); | ||
| 13258 | + child | ||
| 13259 | + .stdin | ||
| 13260 | + .take() | ||
| 13261 | + .expect("aomenc stdin") | ||
| 13262 | + .write_all(&y4m.stdout) | ||
| 13263 | + .expect("writing y4m to aomenc"); | ||
| 13264 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 13265 | + assert!( | ||
| 13266 | + out.status.success(), | ||
| 13267 | + "aomenc refused the fixture: {}", | ||
| 13268 | + String::from_utf8_lossy(&out.stderr) | ||
| 13269 | + ); | ||
| 13270 | + let stream = out.stdout; | ||
| 13271 | + let before = ( | ||
| 13272 | + crate::decode::rect4_32_horz_hits(), | ||
| 13273 | + crate::decode::rect4_32_vert_hits(), | ||
| 13274 | + crate::decode::rect4_coeff_hits(), | ||
| 13275 | + ); | ||
| 13276 | + let frames = match decode_stream(&stream) { | ||
| 13277 | + Err(e) => { | ||
| 13278 | + let msg = e.to_string(); | ||
| 13279 | + assert!( | ||
| 13280 | + msg.contains("unsupported"), | ||
| 13281 | + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, seed \ | ||
| 13282 | + {seed}): {msg}" | ||
| 13283 | + ); | ||
| 13284 | + named_refusals += 1; | ||
| 13285 | + eprintln!("{bit_depth}-bit seed {seed} refusal: {msg}"); | ||
| 13286 | + continue; | ||
| 13287 | + } | ||
| 13288 | + Ok(frames) => frames, | ||
| 13289 | + }; | ||
| 13290 | + let (horz, vert, coeff) = ( | ||
| 13291 | + crate::decode::rect4_32_horz_hits() - before.0, | ||
| 13292 | + crate::decode::rect4_32_vert_hits() - before.1, | ||
| 13293 | + crate::decode::rect4_coeff_hits() - before.2, | ||
| 13294 | + ); | ||
| 13295 | + let ffmpeg_frames = if bit_depth == 10 { | ||
| 13296 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 13297 | + } else { | ||
| 13298 | + ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 13299 | + }; | ||
| 13300 | + assert_eq!(frames.len(), frame_count); | ||
| 13301 | + let mismatched = frames | ||
| 13302 | + .iter() | ||
| 13303 | + .zip(&ffmpeg_frames) | ||
| 13304 | + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | ||
| 13305 | + if horz + vert == 0 { | ||
| 13306 | + // Out of this gate's territory (no 32-level 1:4 block in | ||
| 13307 | + // the stream): counted and printed, never silently | ||
| 13308 | + // dropped, and a mismatch here is another shape's defect. | ||
| 13309 | + out_of_scope += 1; | ||
| 13310 | + if mismatched { | ||
| 13311 | + out_of_scope_mismatch += 1; | ||
| 13312 | + eprintln!( | ||
| 13313 | + "{NAME}: {bit_depth}-bit seed {seed} MISMATCHES with zero 32-level \ | ||
| 13314 | + 1:4 blocks -- a pre-existing defect of another shape" | ||
| 13315 | + ); | ||
| 13316 | + } | ||
| 13317 | + continue; | ||
| 13318 | + } | ||
| 13319 | + if mismatched { | ||
| 13320 | + if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { | ||
| 13321 | + std::fs::write(&path, &stream).expect("writing pinned stream"); | ||
| 13322 | + eprintln!( | ||
| 13323 | + "EC_AV1_GATE_DUMP: wrote mismatching stream ({bit_depth}-bit, seed \ | ||
| 13324 | + {seed}) to {path}" | ||
| 13325 | + ); | ||
| 13326 | + } | ||
| 13327 | + } | ||
| 13328 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 13329 | + assert_eq!( | ||
| 13330 | + got.y, want.y, | ||
| 13331 | + "{NAME} frame {i} luma vs ffmpeg ({bit_depth}-bit, seed {seed})" | ||
| 13332 | + ); | ||
| 13333 | + assert_eq!( | ||
| 13334 | + got.u, want.u, | ||
| 13335 | + "{NAME} frame {i} U vs ffmpeg ({bit_depth}-bit, seed {seed})" | ||
| 13336 | + ); | ||
| 13337 | + assert_eq!( | ||
| 13338 | + got.v, want.v, | ||
| 13339 | + "{NAME} frame {i} V vs ffmpeg ({bit_depth}-bit, seed {seed})" | ||
| 13340 | + ); | ||
| 13341 | + } | ||
| 13342 | + horz_proved += horz; | ||
| 13343 | + vert_proved += vert; | ||
| 13344 | + coeff_proved += coeff; | ||
| 13345 | + matched += 1; | ||
| 13346 | + } | ||
| 13347 | + assert!( | ||
| 13348 | + matched > 0, | ||
| 13349 | + "{NAME}: every {bit_depth}-bit attempt refused; the gate never decoded a stream" | ||
| 13350 | + ); | ||
| 13351 | + assert!( | ||
| 13352 | + horz_proved > 0 && vert_proved > 0, | ||
| 13353 | + "{NAME}: a 32-level 1:4 arm never fired inside a pixel-exact {bit_depth}-bit \ | ||
| 13354 | + attempt (horz={horz_proved}, vert={vert_proved}, {matched} matches, \ | ||
| 13355 | + {named_refusals} refusals out of {n_attempts}) -- gate proved nothing this run" | ||
| 13356 | + ); | ||
| 13357 | + assert!( | ||
| 13358 | + coeff_proved > 0, | ||
| 13359 | + "{NAME}: every {bit_depth}-bit 32-level 1:4 strip was skip -- the 32x8/16x4 \ | ||
| 13360 | + coefficient tables were never read" | ||
| 13361 | + ); | ||
| 13362 | + eprintln!( | ||
| 13363 | + "{NAME}: {bit_depth}-bit: {named_refusals} named refusals, {matched} pixel-exact \ | ||
| 13364 | + matches out of {n_attempts}, horz_4 strips={horz_proved}, vert_4 \ | ||
| 13365 | + strips={vert_proved}, coded strips={coeff_proved}, {out_of_scope} attempts \ | ||
| 13366 | + carried no 32-level 1:4 block ({out_of_scope_mismatch} mismatched)" | ||
| 13367 | + ); | ||
| 13368 | + } | ||
| 13369 | + } | ||
| 13135 | } | 13370 | } |