TX_4X8/TX_8X4 leaves below 8x8 -- rect scan, 32-position eob_pt, TX_8X8 coeff tables with a TX_4X4 tx_type row (gate still RED)
Browse files at this commitd471e3efbb4788bd7a4b24585ea5d7c488dcd39dParent: 47ca477- feat
- TX_4X8/TX_8X4 leaves below 8x8 -- rect scan, 32-position eob_pt, TX_8X8 coeff tables with a TX_4X4 tx_type row (gate still RED)
7 changed files +896 -39
- crates/ec-av1/src/cdf.rs +24 -0
- crates/ec-av1/src/cdf_state.rs +59 -0
- crates/ec-av1/src/decode.rs +479 -34
- crates/ec-av1/src/encode.rs +41 -2
- crates/ec-av1/src/refusal_inventory.rs +0 -3
- crates/ec-av1/src/stream.rs +201 -0
- lanes/tx4x8-r1.report.md +92 -0
crates/ec-av1/src/cdf.rsmodified+24 -0
| @@ -4616,6 +4616,30 @@ pub const EOB_PT_16_LUMA_Q3: [u16; 6] = [6708, 8958, 14746, 22133, 32768, 0]; | ||
| 4616 | 4616 | /// `V_DCT`/`H_DCT` (lane-av1tx4 r5: the class dimension libaom always keeps, |
| 4617 | 4617 | /// this crate never carried at all until a real aomdec trace showed the |
| 4618 | 4618 | /// desync starting exactly at this read). |
| 4619 | +/// `av1_default_eob_multi32_cdfs` (libaom `token_cdfs.h`), luma plane, 2D tx | |
| 4620 | +/// class: the end-of-block group of a 32-position transform -- the | |
| 4621 | +/// `TX_4X8`/`TX_8X4` pair this decoder reaches through | |
| 4622 | +/// [`crate::cdf_state::TxbSet::LumaRect4x8`] (lane-tx4x8). Q-context 2 | |
| 4623 | +/// (`base_q_idx` 61..=120) is the unsuffixed name, as everywhere else here. | |
| 4624 | +pub const EOB_PT_32_LUMA_Q0: [u16; 7] = [400, 520, 977, 2102, 6542, 32768, 0]; | |
| 4625 | +/// [`EOB_PT_32_LUMA_Q0`]'s q-context 1 (`base_q_idx` 21..=60) sibling. | |
| 4626 | +pub const EOB_PT_32_LUMA_Q1: [u16; 7] = [989, 1249, 2019, 4151, 10785, 32768, 0]; | |
| 4627 | +/// [`EOB_PT_32_LUMA_Q0`]'s q-context 2 (`base_q_idx` 61..=120) sibling. | |
| 4628 | +pub const EOB_PT_32_LUMA: [u16; 7] = [2515, 3003, 4452, 8162, 16041, 32768, 0]; | |
| 4629 | +/// [`EOB_PT_32_LUMA_Q0`]'s q-context 3 (`base_q_idx` 121..=255) sibling. | |
| 4630 | +pub const EOB_PT_32_LUMA_Q3: [u16; 7] = [4617, 5709, 8446, 13584, 23135, 32768, 0]; | |
| 4631 | +/// [`EOB_PT_32_LUMA`]'s `TX_CLASS_HORIZ`/`TX_CLASS_VERT` sibling (the `[1]` | |
| 4632 | +/// row of the same libaom table), read instead whenever the TU's `tx_type` | |
| 4633 | +/// is `V_DCT`/`H_DCT` -- reachable at 4x8/8x4 because that size's intra | |
| 4634 | +/// `tx_type` set is `EXT_TX_SET_DTT4_IDTX_1DDCT`, which carries both. | |
| 4635 | +pub const EOB_PT_32_LUMA_CLASS1_Q0: [u16; 7] = [210, 405, 1315, 3326, 7537, 32768, 0]; | |
| 4636 | +/// [`EOB_PT_32_LUMA_CLASS1_Q0`]'s q-context 1 sibling. | |
| 4637 | +pub const EOB_PT_32_LUMA_CLASS1_Q1: [u16; 7] = [313, 441, 1099, 2917, 8562, 32768, 0]; | |
| 4638 | +/// [`EOB_PT_32_LUMA_CLASS1_Q0`]'s q-context 2 sibling. | |
| 4639 | +pub const EOB_PT_32_LUMA_CLASS1: [u16; 7] = [574, 821, 1836, 5089, 13128, 32768, 0]; | |
| 4640 | +/// [`EOB_PT_32_LUMA_CLASS1_Q0`]'s q-context 3 sibling. | |
| 4641 | +pub const EOB_PT_32_LUMA_CLASS1_Q3: [u16; 7] = [1156, 1702, 3675, 9274, 20539, 32768, 0]; | |
| 4642 | + | |
| 4619 | 4643 | pub const EOB_PT_16_LUMA_CLASS1_Q0: [u16; 6] = [370, 671, 1883, 4471, 32768, 0]; |
| 4620 | 4644 | pub const EOB_PT_16_LUMA_CLASS1_Q1: [u16; 6] = [513, 765, 1859, 6339, 32768, 0]; |
| 4621 | 4645 | pub const EOB_PT_16_LUMA_CLASS1: [u16; 6] = [716, 1105, 2646, 10056, 32768, 0]; |
crates/ec-av1/src/cdf_state.rsmodified+59 -0
| @@ -117,6 +117,20 @@ pub(crate) enum TxbSet { | ||
| 117 | 117 | /// different existing sets is why this variant exists at all rather than |
| 118 | 118 | /// reusing [`LumaRect32x16`](TxbSet::LumaRect32x16)'s chroma sibling. |
| 119 | 119 | ChromaRect32x16, |
| 120 | + /// The luma 4x8/8x4 transform of a `PARTITION_VERT`/`HORZ` leaf under an | |
| 121 | + /// 8x8 block (lane-tx4x8), under this encoder's `reduced_tx_set`. | |
| 122 | + /// `get_txsize_entropy_ctx` ((`txsize_sqr_map` + `txsize_sqr_up_map` + 1) | |
| 123 | + /// >> 1) resolves `TX_4X8` to `TX_8X8`, so every coefficient table here is | |
| 124 | + /// [`Luma8`](TxbSet::Luma8)'s -- except `eob_pt`, a true 32-position | |
| 125 | + /// alphabet ([`crate::cdf::EOB_PT_32_LUMA`]), and `tx_type`, whose CDF row | |
| 126 | + /// is `txsize_sqr_map[TX_4X8]` = `TX_4X4` (libaom `read_tx_type`'s | |
| 127 | + /// `square_tx_size`), i.e. [`Luma4`](TxbSet::Luma4)'s own table. | |
| 128 | + LumaRect4x8, | |
| 129 | + /// [`LumaRect4x8`](TxbSet::LumaRect4x8)'s `reduced_tx_set: false` | |
| 130 | + /// counterpart: `av1_get_ext_tx_set_type` at `tx_size_sqr_up == TX_8X8`, | |
| 131 | + /// `tx_size_sqr == TX_4X4`, intra returns `EXT_TX_SET_DTT4_IDTX_1DDCT`, | |
| 132 | + /// the same seven-symbol set (and same `TX_4X4` row) `Luma4Set1` reads. | |
| 133 | + LumaRect4x8Set1, | |
| 120 | 134 | } |
| 121 | 135 | |
| 122 | 136 | /// The tables one transform block is coded with, borrowed from the state for |
| @@ -200,6 +214,11 @@ pub(crate) struct Cdfs { | ||
| 200 | 214 | pub eob_pt_16_luma_class1: [u16; 6], |
| 201 | 215 | /// `eob_pt_64_luma`'s class-1 sibling (r5), see `eob_pt_16_luma_class1`. |
| 202 | 216 | pub eob_pt_64_luma_class1: [u16; 8], |
| 217 | + /// The end-of-block group of a 32-position (4x8/8x4) luma transform | |
| 218 | + /// (lane-tx4x8). | |
| 219 | + pub eob_pt_32_luma: [u16; 7], | |
| 220 | + /// `eob_pt_32_luma`'s class-1 sibling, see `eob_pt_16_luma_class1`. | |
| 221 | + pub eob_pt_32_luma_class1: [u16; 7], | |
| 203 | 222 | /// The end-of-block offset bit of a 16x16 luma transform. |
| 204 | 223 | pub eob_extra_luma_16: [[u16; 3]; 9], |
| 205 | 224 | /// The same, for an 8x8 luma transform. |
| @@ -592,6 +611,8 @@ impl Cdfs { | ||
| 592 | 611 | reset1(&mut self.eob_pt_16_luma); |
| 593 | 612 | reset1(&mut self.eob_pt_16_luma_class1); |
| 594 | 613 | reset1(&mut self.eob_pt_64_luma_class1); |
| 614 | + reset1(&mut self.eob_pt_32_luma); | |
| 615 | + reset1(&mut self.eob_pt_32_luma_class1); | |
| 595 | 616 | reset2(&mut self.eob_extra_luma_16); |
| 596 | 617 | reset2(&mut self.eob_extra_luma_8); |
| 597 | 618 | reset2(&mut self.eob_extra_luma_4); |
| @@ -798,6 +819,20 @@ impl Cdfs { | ||
| 798 | 819 | cdf::EOB_PT_16_LUMA_CLASS1, |
| 799 | 820 | cdf::EOB_PT_16_LUMA_CLASS1_Q3, |
| 800 | 821 | ), |
| 822 | + eob_pt_32_luma: pick( | |
| 823 | + q_ctx, | |
| 824 | + cdf::EOB_PT_32_LUMA_Q0, | |
| 825 | + cdf::EOB_PT_32_LUMA_Q1, | |
| 826 | + cdf::EOB_PT_32_LUMA, | |
| 827 | + cdf::EOB_PT_32_LUMA_Q3, | |
| 828 | + ), | |
| 829 | + eob_pt_32_luma_class1: pick( | |
| 830 | + q_ctx, | |
| 831 | + cdf::EOB_PT_32_LUMA_CLASS1_Q0, | |
| 832 | + cdf::EOB_PT_32_LUMA_CLASS1_Q1, | |
| 833 | + cdf::EOB_PT_32_LUMA_CLASS1, | |
| 834 | + cdf::EOB_PT_32_LUMA_CLASS1_Q3, | |
| 835 | + ), | |
| 801 | 836 | eob_pt_64_luma_class1: pick( |
| 802 | 837 | q_ctx, |
| 803 | 838 | cdf::EOB_PT_64_LUMA_CLASS1_Q0, |
| @@ -1409,6 +1444,30 @@ impl Cdfs { | ||
| 1409 | 1444 | tx_type: None, |
| 1410 | 1445 | eob_pt_class1: None, |
| 1411 | 1446 | }, |
| 1447 | + TxbSet::LumaRect4x8 => TxbTables { | |
| 1448 | + side: 8, | |
| 1449 | + txb_skip: &mut self.txb_skip_luma_8, | |
| 1450 | + eob_pt: &mut self.eob_pt_32_luma, | |
| 1451 | + eob_extra: &mut self.eob_extra_luma_8, | |
| 1452 | + base: &mut self.base_luma_8, | |
| 1453 | + base_eob: &mut self.base_eob_luma_8, | |
| 1454 | + br: &mut self.br_luma_8, | |
| 1455 | + dc_sign: &mut self.dc_sign_luma, | |
| 1456 | + tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()), | |
| 1457 | + eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), | |
| 1458 | + }, | |
| 1459 | + TxbSet::LumaRect4x8Set1 => TxbTables { | |
| 1460 | + side: 8, | |
| 1461 | + txb_skip: &mut self.txb_skip_luma_8, | |
| 1462 | + eob_pt: &mut self.eob_pt_32_luma, | |
| 1463 | + eob_extra: &mut self.eob_extra_luma_8, | |
| 1464 | + base: &mut self.base_luma_8, | |
| 1465 | + base_eob: &mut self.base_eob_luma_8, | |
| 1466 | + br: &mut self.br_luma_8, | |
| 1467 | + dc_sign: &mut self.dc_sign_luma, | |
| 1468 | + tx_type: Some(self.intra_tx_type_4_set1[mode].as_mut_slice()), | |
| 1469 | + eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), | |
| 1470 | + }, | |
| 1412 | 1471 | TxbSet::ChromaRect32x16 => TxbTables { |
| 1413 | 1472 | side: 32, |
| 1414 | 1473 | txb_skip: &mut self.txb_skip_chroma_32, |
crates/ec-av1/src/decode.rsmodified+479 -34
| @@ -935,6 +935,26 @@ thread_local! { | ||
| 935 | 935 | pub(crate) fn sub8_split_hits() -> usize { |
| 936 | 936 | SUB8_SPLIT_HITS.with(|c| c.get()) |
| 937 | 937 | } |
| 938 | + | |
| 939 | +// How many 4x8 / 8x4 leaves (lane-tx4x8's `PARTITION_VERT`/`PARTITION_HORZ` | |
| 940 | +// of an 8x8 block) this thread's decode reconstructed with REAL coefficients | |
| 941 | +// -- a skipped leaf exercises the prediction and the mi bookkeeping but never | |
| 942 | +// the rect transform, the 32-position `eob_pt` or the rect scan, so the gate | |
| 943 | +// asserts on these two rather than a plain leaf count. | |
| 944 | +thread_local! { | |
| 945 | + static TX4X8_CODED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 946 | + static TX8X4_CODED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 947 | +} | |
| 948 | + | |
| 949 | +/// Current value of [`TX4X8_CODED_HITS`]. | |
| 950 | +pub(crate) fn tx4x8_coded_hits() -> usize { | |
| 951 | + TX4X8_CODED_HITS.with(|c| c.get()) | |
| 952 | +} | |
| 953 | + | |
| 954 | +/// Current value of [`TX8X4_CODED_HITS`]. | |
| 955 | +pub(crate) fn tx8x4_coded_hits() -> usize { | |
| 956 | + TX8X4_CODED_HITS.with(|c| c.get()) | |
| 957 | +} | |
| 938 | 958 | const SUB_MI: u32 = 4; |
| 939 | 959 | const MI: usize = 4; |
| 940 | 960 | const SB: usize = 64; |
| @@ -1030,10 +1050,20 @@ fn default_scan(side: usize) -> Vec<u16> { | ||
| 1030 | 1050 | /// `0..side*side` in our own indexing — and `Mcol_Scan` is that walk |
| 1031 | 1051 | /// transposed (column 0 down every row, then column 1, ...). |
| 1032 | 1052 | fn class_scan_table(side: usize, class: TxClass) -> Vec<u16> { |
| 1053 | + class_scan_table_wh(side, side, class) | |
| 1054 | +} | |
| 1055 | + | |
| 1056 | +/// [`class_scan_table`] widened to `(w, h)` (lane-tx4x8). Checked against | |
| 1057 | +/// libaom's own `mrow_scan_4x8`/`mcol_scan_4x8`/`mrow_scan_8x4`/ | |
| 1058 | +/// `mcol_scan_8x4` (`scan.c`) converted out of their column-major encoding | |
| 1059 | +/// by `(p % h) * w + p / h`, the same conversion [`SCAN_16X8`] was | |
| 1060 | +/// transcribed with -- `mrow` is the plain row-major raster in our indexing | |
| 1061 | +/// and `mcol` its transpose, at rect sizes exactly as at square ones. | |
| 1062 | +fn class_scan_table_wh(w: usize, h: usize, class: TxClass) -> Vec<u16> { | |
| 1033 | 1063 | match class { |
| 1034 | - TxClass::Vert => (0..(side * side) as u16).collect(), | |
| 1035 | - TxClass::Horiz => (0..side) | |
| 1036 | - .flat_map(|col| (0..side).map(move |row| (row * side + col) as u16)) | |
| 1064 | + TxClass::Vert => (0..(w * h) as u16).collect(), | |
| 1065 | + TxClass::Horiz => (0..w) | |
| 1066 | + .flat_map(|col| (0..h).map(move |row| (row * w + col) as u16)) | |
| 1037 | 1067 | .collect(), |
| 1038 | 1068 | TxClass::TwoD => unreachable!("class_scan is only for V_DCT/H_DCT"), |
| 1039 | 1069 | } |
| @@ -1229,6 +1259,21 @@ const SCAN_16X32: [u16; 512] = [ | ||
| 1229 | 1259 | 491, 506, 447, 462, 477, 492, 507, 463, 478, 493, 508, 479, 494, 509, 495, 510, 511, |
| 1230 | 1260 | ]; |
| 1231 | 1261 | |
| 1262 | +/// `Default_Scan_4x8` (libaom `scan.c`), this decoder's own row-major | |
| 1263 | +/// transcription (see [`SCAN_32X16`]'s doc comment for the conversion, which | |
| 1264 | +/// was re-verified this lane by regenerating [`SCAN_16X8`]/[`SCAN_8X16`] from | |
| 1265 | +/// the same source). | |
| 1266 | +const SCAN_4X8: [u16; 32] = [ | |
| 1267 | + 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, | |
| 1268 | + 23, 26, 29, 27, 30, 31, | |
| 1269 | +]; | |
| 1270 | + | |
| 1271 | +/// `Default_Scan_8x4`, same source and conversion as [`SCAN_4X8`]. | |
| 1272 | +const SCAN_8X4: [u16; 32] = [ | |
| 1273 | + 0, 8, 1, 16, 9, 2, 24, 17, 10, 3, 25, 18, 11, 4, 26, 19, 12, 5, 27, 20, 13, 6, 28, 21, 14, 7, | |
| 1274 | + 29, 22, 15, 30, 23, 31, | |
| 1275 | +]; | |
| 1276 | + | |
| 1232 | 1277 | /// `Default_Scan_16x8`, this decoder's own row-major transcription (see |
| 1233 | 1278 | /// [`SCAN_32X16`]'s doc comment). |
| 1234 | 1279 | const SCAN_16X8: [u16; 128] = [ |
| @@ -1268,30 +1313,63 @@ fn neighbour_rect(grid: &[i32], w: usize, h: usize, row: usize, col: usize) -> i | ||
| 1268 | 1313 | /// same [`cdf::NZ_MAP_CTX_OFFSET_32`] table when `w == h`. Never called for |
| 1269 | 1314 | /// `V_DCT`/`H_DCT` -- geometrically impossible at the two size pairs |
| 1270 | 1315 | /// [`decode_block_rect`] codes (see that function's own doc comment). |
| 1271 | -fn base_ctx_rect(grid: &[i32], w: usize, h: usize, row: usize, col: usize) -> usize { | |
| 1272 | - if row == 0 && col == 0 { | |
| 1316 | +fn base_ctx_rect( | |
| 1317 | + grid: &[i32], | |
| 1318 | + w: usize, | |
| 1319 | + h: usize, | |
| 1320 | + row: usize, | |
| 1321 | + col: usize, | |
| 1322 | + class: TxClass, | |
| 1323 | +) -> usize { | |
| 1324 | + // Same `(tx_class | coeff_idx) == 0` guard [`base_ctx`] documents: only | |
| 1325 | + // the 2D class short-circuits the DC position. | |
| 1326 | + if class == TxClass::TwoD && row == 0 && col == 0 { | |
| 1273 | 1327 | return 0; |
| 1274 | 1328 | } |
| 1275 | - const OFFSETS: [(usize, usize); 5] = [(1, 0), (0, 1), (1, 1), (2, 0), (0, 2)]; | |
| 1276 | - let mag: i32 = OFFSETS | |
| 1329 | + let offsets: [(usize, usize); 5] = match class { | |
| 1330 | + TxClass::TwoD => [(1, 0), (0, 1), (1, 1), (2, 0), (0, 2)], | |
| 1331 | + TxClass::Horiz => [(1, 0), (0, 1), (0, 2), (0, 3), (0, 4)], | |
| 1332 | + TxClass::Vert => [(1, 0), (0, 1), (2, 0), (3, 0), (4, 0)], | |
| 1333 | + }; | |
| 1334 | + let mag: i32 = offsets | |
| 1277 | 1335 | .iter() |
| 1278 | 1336 | .map(|&(dr, dc)| neighbour_rect(grid, w, h, row + dr, col + dc).abs().min(3)) |
| 1279 | 1337 | .sum(); |
| 1280 | 1338 | let ctx = ((mag + 1) >> 1).min(4) as usize; |
| 1281 | - if w < h && row < 2 { | |
| 1282 | - return ctx + 11; | |
| 1283 | - } | |
| 1284 | - if w > h && col < 2 { | |
| 1285 | - return ctx + 16; | |
| 1339 | + match class { | |
| 1340 | + TxClass::TwoD => { | |
| 1341 | + if w < h && row < 2 { | |
| 1342 | + return ctx + 11; | |
| 1343 | + } | |
| 1344 | + if w > h && col < 2 { | |
| 1345 | + return ctx + 16; | |
| 1346 | + } | |
| 1347 | + ctx + cdf::NZ_MAP_CTX_OFFSET_32[row.min(4)][col.min(4)] as usize | |
| 1348 | + } | |
| 1349 | + // Shape-independent in libaom too (`get_nz_map_ctx_from_stats`'s | |
| 1350 | + // `TX_CLASS_HORIZ`/`VERT` arms index `nz_map_ctx_offset_1d` by the | |
| 1351 | + // position along one axis only). | |
| 1352 | + TxClass::Horiz => ctx + nz_map_ctx_offset_1d(col.min(31)), | |
| 1353 | + TxClass::Vert => ctx + nz_map_ctx_offset_1d(row.min(31)), | |
| 1286 | 1354 | } |
| 1287 | - ctx + cdf::NZ_MAP_CTX_OFFSET_32[row.min(4)][col.min(4)] as usize | |
| 1288 | 1355 | } |
| 1289 | 1356 | |
| 1290 | 1357 | /// [`br_ctx`]'s `TxClass::TwoD` arm widened to `(w, h)` (lane-rectwire): the |
| 1291 | 1358 | /// neighbour-offset math itself is shape-independent, only the boundary |
| 1292 | 1359 | /// clamp needs the real bound in each axis. |
| 1293 | -fn br_ctx_rect(grid: &[i32], w: usize, h: usize, row: usize, col: usize) -> usize { | |
| 1294 | - let extra = neighbour_rect(grid, w, h, row + 1, col + 1).abs(); | |
| 1360 | +fn br_ctx_rect( | |
| 1361 | + grid: &[i32], | |
| 1362 | + w: usize, | |
| 1363 | + h: usize, | |
| 1364 | + row: usize, | |
| 1365 | + col: usize, | |
| 1366 | + class: TxClass, | |
| 1367 | +) -> usize { | |
| 1368 | + let extra = match class { | |
| 1369 | + TxClass::TwoD => neighbour_rect(grid, w, h, row + 1, col + 1).abs(), | |
| 1370 | + TxClass::Horiz => neighbour_rect(grid, w, h, row, col + 2).abs(), | |
| 1371 | + TxClass::Vert => neighbour_rect(grid, w, h, row + 2, col).abs(), | |
| 1372 | + }; | |
| 1295 | 1373 | let mag = neighbour_rect(grid, w, h, row + 1, col).abs() |
| 1296 | 1374 | + neighbour_rect(grid, w, h, row, col + 1).abs() |
| 1297 | 1375 | + extra; |
| @@ -1299,7 +1377,12 @@ fn br_ctx_rect(grid: &[i32], w: usize, h: usize, row: usize, col: usize) -> usiz | ||
| 1299 | 1377 | if row == 0 && col == 0 { |
| 1300 | 1378 | return mag; |
| 1301 | 1379 | } |
| 1302 | - if row < 2 && col < 2 { mag + 7 } else { mag + 14 } | |
| 1380 | + let near_origin = match class { | |
| 1381 | + TxClass::TwoD => row < 2 && col < 2, | |
| 1382 | + TxClass::Horiz => col == 0, | |
| 1383 | + TxClass::Vert => row == 0, | |
| 1384 | + }; | |
| 1385 | + if near_origin { mag + 7 } else { mag + 14 } | |
| 1303 | 1386 | } |
| 1304 | 1387 | |
| 1305 | 1388 | fn dc_vote(dc: Option<bool>) -> i32 { |
| @@ -1635,18 +1718,36 @@ fn read_coeffs_rect( | ||
| 1635 | 1718 | if all_zero { |
| 1636 | 1719 | return Ok((grid, TxType::DctDct)); |
| 1637 | 1720 | } |
| 1638 | - if coding.tx_type.is_some() { | |
| 1639 | - return Err(unsupported( | |
| 1640 | - "a tx_type symbol on a rectangular transform (never expected at this size)", | |
| 1641 | - )); | |
| 1721 | + // lane-tx4x8: a 4x8/8x4 luma TU DOES carry a `tx_type` symbol (its set is | |
| 1722 | + // `EXT_TX_SET_DTT4_IDTX(_1DDCT)`, `tx_size_sqr_up == TX_8X8`), including | |
| 1723 | + // the `V_DCT`/`H_DCT` members whose 1D tx class needs its own scan and | |
| 1724 | + // context offsets -- both of which now have rect forms | |
| 1725 | + // ([`class_scan_table_wh`], [`base_ctx_rect`]/[`br_ctx_rect`]'s `class`). | |
| 1726 | + // The rect sets that carry no symbol at all still pass `None` here. | |
| 1727 | + let mut tx_type = default_tx_type; | |
| 1728 | + if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() { | |
| 1729 | + let len = tx_type_cdf.len(); | |
| 1730 | + let t = dec.symbol(tx_type_cdf); | |
| 1731 | + tx_type = match len { | |
| 1732 | + 17 => TxType::from_symbol_all16(t), | |
| 1733 | + 13 => TxType::from_symbol_set2_12(t), | |
| 1734 | + 8 => TxType::from_symbol_set1(t), | |
| 1735 | + _ => TxType::from_symbol(t), | |
| 1736 | + } | |
| 1737 | + .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; | |
| 1642 | 1738 | } |
| 1643 | - let tx_type = default_tx_type; | |
| 1644 | - if TxClass::of(tx_type) != TxClass::TwoD { | |
| 1645 | - return Err(unsupported( | |
| 1646 | - "a non-2D tx class on a rectangular transform (never expected at this size)", | |
| 1647 | - )); | |
| 1739 | + let class = TxClass::of(tx_type); | |
| 1740 | + if class != TxClass::TwoD { | |
| 1741 | + TX_CLASS1_HITS.with(|c| c.set(c.get() + 1)); | |
| 1648 | 1742 | } |
| 1649 | - let eob = read_eob(dec, coding, TxClass::TwoD); | |
| 1743 | + let eob = read_eob(dec, coding, class); | |
| 1744 | + let class_scan; | |
| 1745 | + let scan: &[u16] = if class == TxClass::TwoD { | |
| 1746 | + scan | |
| 1747 | + } else { | |
| 1748 | + class_scan = class_scan_table_wh(w, h, class); | |
| 1749 | + &class_scan | |
| 1750 | + }; | |
| 1650 | 1751 | let mut levels = vec![0i32; w * h]; |
| 1651 | 1752 | for scan_idx in (0..eob).rev() { |
| 1652 | 1753 | let pos = scan[scan_idx] as usize; |
| @@ -1655,11 +1756,11 @@ fn read_coeffs_rect( | ||
| 1655 | 1756 | let ctx = eob_coeff_ctx(scan_idx, w * h); |
| 1656 | 1757 | dec.symbol(&mut coding.base_eob[ctx]) as i32 + 1 |
| 1657 | 1758 | } else { |
| 1658 | - let ctx = base_ctx_rect(&levels, w, h, row, col); | |
| 1759 | + let ctx = base_ctx_rect(&levels, w, h, row, col, class); | |
| 1659 | 1760 | dec.symbol(&mut coding.base[ctx]) as i32 |
| 1660 | 1761 | }; |
| 1661 | 1762 | let level = if level > NUM_BASE_LEVELS { |
| 1662 | - let ctx = br_ctx_rect(&levels, w, h, row, col); | |
| 1763 | + let ctx = br_ctx_rect(&levels, w, h, row, col, class); | |
| 1663 | 1764 | let mut level = level; |
| 1664 | 1765 | let mut sent = 0; |
| 1665 | 1766 | loop { |
| @@ -5916,6 +6017,228 @@ fn decode_leaf_split4( | ||
| 5916 | 6017 | Ok((leaf_modes[2], leaf_modes[1])) |
| 5917 | 6018 | } |
| 5918 | 6019 | |
| 6020 | +/// Decodes a `PARTITION_VERT`/`PARTITION_HORZ` of one 8x8 block into two | |
| 6021 | +/// `BLOCK_4X8`/`BLOCK_8X4` leaves (lane-tx4x8), the last partition shape | |
| 6022 | +/// below 8x8 this decoder refused. Mirrors [`decode_leaf_split4`] element for | |
| 6023 | +/// element -- same mode reads ([`read_intra_mode_sub8`]: no angle delta, no | |
| 6024 | +/// tx-depth symbol below 8x8), same "chroma once, on the last sub-block, at | |
| 6025 | +/// the whole 8x8 group's 4x4 unit" rule (`is_chroma_reference` is false for | |
| 6026 | +/// every sub-block one mi wide or high but the last) -- differing only where | |
| 6027 | +/// the shape does: | |
| 6028 | +/// | |
| 6029 | +/// * the transform is a true `TX_4X8`/`TX_8X4` | |
| 6030 | +/// ([`dequant_and_inverse_typed_wh`], whose `abs(rect_type) == 1` scale and | |
| 6031 | +/// `av1_inv_txfm_shift_ls` row already cover this size pair); | |
| 6032 | +/// * the CDF set is [`TxbSet::LumaRect4x8`] (`get_txsize_entropy_ctx` squares | |
| 6033 | +/// up to `TX_8X8`) with a 32-position `eob_pt` and the `TX_4X4` `tx_type` | |
| 6034 | +/// row -- see that variant's doc comment; | |
| 6035 | +/// * the scan is [`SCAN_4X8`]/[`SCAN_8X4`], or their `mrow`/`mcol` siblings | |
| 6036 | +/// ([`class_scan_table_wh`]) when the coded `tx_type` is `V_DCT`/`H_DCT`; | |
| 6037 | +/// * `Reach` comes from libaom's own `has_tr_4x8`/`has_bl_8x4` rows | |
| 6038 | +/// ([`Reach::of_rect`]); | |
| 6039 | +/// * `update_partition_context` writes `partition_context_lookup[BLOCK_4X8]` | |
| 6040 | +/// = `{31, 30}` (width 4 above, height 8 left), not the `{31, 31}` a | |
| 6041 | +/// `BLOCK_4X4` split writes. | |
| 6042 | +/// | |
| 6043 | +/// Filter intra on one of these leaves is refused by name: `predict_filter_intra` | |
| 6044 | +/// is square-only in this decoder (the same refusal the 16x16-level rect | |
| 6045 | +/// strips already carry). | |
| 6046 | +#[allow(clippy::too_many_arguments)] | |
| 6047 | +fn decode_leaf_rect8( | |
| 6048 | + dec: &mut SymbolDecoder, | |
| 6049 | + cdfs: &mut Cdfs, | |
| 6050 | + neighbours: &mut Neighbours, | |
| 6051 | + outer_at: (usize, usize), | |
| 6052 | + leaf_mi: (usize, usize), | |
| 6053 | + vert: bool, | |
| 6054 | + scan4: &[u16], | |
| 6055 | + y: &mut PlaneBuf, | |
| 6056 | + u: &mut PlaneBuf, | |
| 6057 | + v: &mut PlaneBuf, | |
| 6058 | + base_q_idx: u8, | |
| 6059 | + enable_filter_intra: bool, | |
| 6060 | + allow_intrabc: bool, | |
| 6061 | + reduced_tx_set: bool, | |
| 6062 | +) -> Result<(usize, usize)> { | |
| 6063 | + let (r, c) = outer_at; | |
| 6064 | + let above_mode = neighbours.above_mode[c]; | |
| 6065 | + let left_mode = neighbours.left_mode[r]; | |
| 6066 | + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c); | |
| 6067 | + let (bw, bh) = if vert { (4, 8) } else { (8, 4) }; | |
| 6068 | + let (w_mi, h_mi) = (bw / MI, bh / MI); | |
| 6069 | + let scan: &[u16] = if vert { &SCAN_4X8 } else { &SCAN_8X4 }; | |
| 6070 | + let mut leaf_modes = [0usize; 2]; | |
| 6071 | + let mut leaf_skips = [false; 2]; | |
| 6072 | + let mut last_uv: Option<(usize, i32, Option<(i32, i32)>)> = None; | |
| 6073 | + for i in 0..2usize { | |
| 6074 | + let lmi = if vert { | |
| 6075 | + (leaf_mi.0, leaf_mi.1 + i) | |
| 6076 | + } else { | |
| 6077 | + (leaf_mi.0 + i, leaf_mi.1) | |
| 6078 | + }; | |
| 6079 | + // Inside the pair the sibling is the neighbour on the split axis; | |
| 6080 | + // outside it the mi-granular map, else the coarse 16x16 slot. | |
| 6081 | + let leaf_above = if !vert && i == 1 { | |
| 6082 | + leaf_modes[0] | |
| 6083 | + } else { | |
| 6084 | + neighbours.mode_above_mi(lmi.0, lmi.1).unwrap_or(above_mode) | |
| 6085 | + }; | |
| 6086 | + let leaf_left = if vert && i == 1 { | |
| 6087 | + leaf_modes[0] | |
| 6088 | + } else { | |
| 6089 | + neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode) | |
| 6090 | + }; | |
| 6091 | + let has_chroma = i == 1; | |
| 6092 | + let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1); | |
| 6093 | + let (skip, mode, angle_delta_y, chroma, filter_intra) = read_intra_mode_sub8( | |
| 6094 | + dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, skip_ctx, | |
| 6095 | + allow_intrabc, lmi.0, lmi.1, | |
| 6096 | + )?; | |
| 6097 | + if filter_intra.is_some() { | |
| 6098 | + return Err(unsupported( | |
| 6099 | + "filter intra on a HORZ/VERT strip (this decoder predicts square-only)", | |
| 6100 | + )); | |
| 6101 | + } | |
| 6102 | + leaf_modes[i] = mode; | |
| 6103 | + leaf_skips[i] = skip; | |
| 6104 | + neighbours.record_mode_mi(lmi.0, lmi.1, w_mi, h_mi, mode); | |
| 6105 | + let smooth_neighbor = is_smooth_mode(leaf_above) || is_smooth_mode(leaf_left); | |
| 6106 | + if smooth_neighbor { | |
| 6107 | + SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); | |
| 6108 | + } | |
| 6109 | + let (px, py) = (lmi.1 * MI, lmi.0 * MI); | |
| 6110 | + let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); | |
| 6111 | + let grid = if skip { | |
| 6112 | + let zeros = vec![0i32; bw * bh]; | |
| 6113 | + y.reconstruct_rect( | |
| 6114 | + px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, None, smooth_neighbor, | |
| 6115 | + ); | |
| 6116 | + zeros | |
| 6117 | + } else { | |
| 6118 | + // `plane_bsize == txsize_to_bsize[tx_size]` here too (the leaf's | |
| 6119 | + // luma TU *is* the leaf), so `get_txb_ctx` fixes `txb_skip_ctx` | |
| 6120 | + // at 0 -- see `decode_leaf_split4`'s own note. | |
| 6121 | + let around = neighbours.around_mi_rect(lmi, bw, bh)[0]; | |
| 6122 | + let set = if reduced_tx_set { | |
| 6123 | + TxbSet::LumaRect4x8 | |
| 6124 | + } else { | |
| 6125 | + TxbSet::LumaRect4x8Set1 | |
| 6126 | + }; | |
| 6127 | + let mut coding = cdfs.txb(set, mode); | |
| 6128 | + let (levels, tx_type) = read_coeffs_rect( | |
| 6129 | + dec, | |
| 6130 | + &mut coding, | |
| 6131 | + scan, | |
| 6132 | + bw, | |
| 6133 | + bh, | |
| 6134 | + 0, | |
| 6135 | + dc_sign_ctx(around.2), | |
| 6136 | + TxType::DctDct, | |
| 6137 | + )?; | |
| 6138 | + if levels.iter().any(|&l| l != 0) { | |
| 6139 | + if vert { | |
| 6140 | + TX4X8_CODED_HITS.with(|h| h.set(h.get() + 1)); | |
| 6141 | + } else { | |
| 6142 | + TX8X4_CODED_HITS.with(|h| h.set(h.get() + 1)); | |
| 6143 | + } | |
| 6144 | + } | |
| 6145 | + let residual = dequant_and_inverse_typed_wh( | |
| 6146 | + &levels, | |
| 6147 | + bw, | |
| 6148 | + bh, | |
| 6149 | + crate::decode::bit_depth(), | |
| 6150 | + CURRENT_Q_IDX.with(|q| q.get()), | |
| 6151 | + plane_q_delta(0).0, | |
| 6152 | + plane_q_delta(0).1, | |
| 6153 | + tx_type, | |
| 6154 | + ); | |
| 6155 | + y.reconstruct_rect( | |
| 6156 | + px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, None, smooth_neighbor, | |
| 6157 | + ); | |
| 6158 | + levels | |
| 6159 | + }; | |
| 6160 | + // Plane 0's per-TU coefficient context over this leaf's own mi span | |
| 6161 | + // (`record_mi_luma`'s rect twin -- the chroma planes are written once | |
| 6162 | + // for the whole 8x8 group below). | |
| 6163 | + let state = neighbour_state(&grid); | |
| 6164 | + for cell in 0..h_mi { | |
| 6165 | + if lmi.0 + cell < neighbours.mi_rows { | |
| 6166 | + neighbours.left[lmi.0 + cell][0] = state; | |
| 6167 | + } | |
| 6168 | + } | |
| 6169 | + for cell in 0..w_mi { | |
| 6170 | + if lmi.1 + cell < neighbours.mi_cols { | |
| 6171 | + neighbours.above[lmi.1 + cell][0] = state; | |
| 6172 | + } | |
| 6173 | + } | |
| 6174 | + neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip); | |
| 6175 | + neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, bw as u8, bh as u8, 0); | |
| 6176 | + if has_chroma { | |
| 6177 | + last_uv = chroma; | |
| 6178 | + } | |
| 6179 | + } | |
| 6180 | + let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI); | |
| 6181 | + let (cpx, cpy) = (gpx / 2, gpy / 2); | |
| 6182 | + let group_reach = Reach::of(8, gpx, gpy, y.width, y.height); | |
| 6183 | + let (uv_mode, angle_delta_uv, alpha) = | |
| 6184 | + last_uv.expect("i==1 always sets has_chroma, so chroma is always Some"); | |
| 6185 | + let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; | |
| 6186 | + neighbours.above_uv_mode[c] = uv_predict_mode; | |
| 6187 | + neighbours.left_uv_mode[r] = uv_predict_mode; | |
| 6188 | + neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); | |
| 6189 | + let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[1] { | |
| 6190 | + u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv); | |
| 6191 | + v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv); | |
| 6192 | + (vec![0i32; 16], vec![0i32; 16]) | |
| 6193 | + } else { | |
| 6194 | + let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8)); | |
| 6195 | + let chroma_around = neighbours.around_mi(leaf_mi, 8); | |
| 6196 | + let ug = read_plane( | |
| 6197 | + dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode, | |
| 6198 | + angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx, | |
| 6199 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, | |
| 6200 | + )?; | |
| 6201 | + let vg = read_plane( | |
| 6202 | + dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode, | |
| 6203 | + angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx, | |
| 6204 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, | |
| 6205 | + )?; | |
| 6206 | + (ug, vg) | |
| 6207 | + }; | |
| 6208 | + // `update_partition_context` at the 8x8 level writes | |
| 6209 | + // `partition_context_lookup[subsize]` over the whole 8x8 span: BLOCK_4X8 | |
| 6210 | + // is `{31, 30}` (bit0 set on the above half only), BLOCK_8X4 `{30, 31}` | |
| 6211 | + // -- the mirror of `decode_leaf_split4`'s `{31, 31}`, which | |
| 6212 | + // `partition_ctx_mi` reads back off these side values. | |
| 6213 | + for cell in 0..2 { | |
| 6214 | + neighbours.above_side_mi[leaf_mi.1 + cell] = bw; | |
| 6215 | + neighbours.left_side_mi[leaf_mi.0 + cell] = bh; | |
| 6216 | + } | |
| 6217 | + let round_up_even = |n: usize| n.div_ceil(2) * 2; | |
| 6218 | + let bound_h = round_up_even(neighbours.mi_rows); | |
| 6219 | + let bound_w = round_up_even(neighbours.mi_cols); | |
| 6220 | + let u_state = neighbour_state(&u_grid); | |
| 6221 | + let v_state = neighbour_state(&v_grid); | |
| 6222 | + for cell in 0..2usize { | |
| 6223 | + if cell < 2usize.min(bound_h.saturating_sub(leaf_mi.0)) { | |
| 6224 | + neighbours.left[leaf_mi.0 + cell][1] = u_state; | |
| 6225 | + neighbours.left[leaf_mi.0 + cell][2] = v_state; | |
| 6226 | + } | |
| 6227 | + if cell < 2usize.min(bound_w.saturating_sub(leaf_mi.1)) { | |
| 6228 | + neighbours.above[leaf_mi.1 + cell][1] = u_state; | |
| 6229 | + neighbours.above[leaf_mi.1 + cell][2] = v_state; | |
| 6230 | + } | |
| 6231 | + } | |
| 6232 | + // `(below_mode, right_mode)`: the sub-block a neighbour below sees is the | |
| 6233 | + // bottom one (the second under HORZ, the left one under VERT), the one a | |
| 6234 | + // neighbour to the right sees is the top-right (the second under VERT). | |
| 6235 | + Ok(if vert { | |
| 6236 | + (leaf_modes[0], leaf_modes[1]) | |
| 6237 | + } else { | |
| 6238 | + (leaf_modes[1], leaf_modes[0]) | |
| 6239 | + }) | |
| 6240 | +} | |
| 6241 | + | |
| 5919 | 6242 | /// Spec 7.15.3's `Cdef_Directions`: `(row, col)` offsets for the two primary |
| 5920 | 6243 | /// taps of each of the eight directions; the secondary taps at `dir+2`/`dir-2` |
| 5921 | 6244 | /// (mod 8) reuse the same table. |
| @@ -7629,10 +7952,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 7629 | 7952 | allow_intrabc, |
| 7630 | 7953 | reduced_tx_set, |
| 7631 | 7954 | )? |
| 7955 | + } else if part8 == PARTITION_HORZ | |
| 7956 | + || part8 == PARTITION_VERT | |
| 7957 | + { | |
| 7958 | + decode_leaf_rect8( | |
| 7959 | + &mut dec, | |
| 7960 | + &mut cdfs, | |
| 7961 | + &mut neighbours, | |
| 7962 | + at16, | |
| 7963 | + leaf_mi, | |
| 7964 | + part8 == PARTITION_VERT, | |
| 7965 | + &scan4, | |
| 7966 | + &mut y, | |
| 7967 | + &mut u, | |
| 7968 | + &mut v, | |
| 7969 | + base_q_idx, | |
| 7970 | + enable_filter_intra, | |
| 7971 | + allow_intrabc, | |
| 7972 | + reduced_tx_set, | |
| 7973 | + )? | |
| 7632 | 7974 | } else { |
| 7633 | - return Err(unsupported( | |
| 7634 | - "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)", | |
| 7635 | - )); | |
| 7975 | + unreachable!("partition_w8 is a 4-symbol CDF: NONE/HORZ/VERT/SPLIT only"); | |
| 7636 | 7976 | }; |
| 7637 | 7977 | neighbours.above_mode[sc] = saved_modes.0; |
| 7638 | 7978 | neighbours.left_mode[sr] = saved_modes.1; |
| @@ -7738,10 +8078,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 7738 | 8078 | allow_intrabc, |
| 7739 | 8079 | reduced_tx_set, |
| 7740 | 8080 | )? |
| 8081 | + } else if part8 == PARTITION_HORZ | |
| 8082 | + || part8 == PARTITION_VERT | |
| 8083 | + { | |
| 8084 | + decode_leaf_rect8( | |
| 8085 | + &mut dec, | |
| 8086 | + &mut cdfs, | |
| 8087 | + &mut neighbours, | |
| 8088 | + at16, | |
| 8089 | + leaf_mi, | |
| 8090 | + part8 == PARTITION_VERT, | |
| 8091 | + &scan4, | |
| 8092 | + &mut y, | |
| 8093 | + &mut u, | |
| 8094 | + &mut v, | |
| 8095 | + base_q_idx, | |
| 8096 | + enable_filter_intra, | |
| 8097 | + allow_intrabc, | |
| 8098 | + reduced_tx_set, | |
| 8099 | + )? | |
| 7741 | 8100 | } else { |
| 7742 | - return Err(unsupported( | |
| 7743 | - "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)", | |
| 7744 | - )); | |
| 8101 | + unreachable!("partition_w8 is a 4-symbol CDF: NONE/HORZ/VERT/SPLIT only"); | |
| 7745 | 8102 | }; |
| 7746 | 8103 | neighbours.above_mode[sc] = saved_modes.0; |
| 7747 | 8104 | neighbours.left_mode[sr] = saved_modes.1; |
| @@ -14809,3 +15166,91 @@ mod tests { | ||
| 14809 | 15166 | } |
| 14810 | 15167 | } |
| 14811 | 15168 | } |
| 15169 | + | |
| 15170 | +#[cfg(test)] | |
| 15171 | +mod tx4x8_table_tests { | |
| 15172 | + use super::*; | |
| 15173 | + | |
| 15174 | + /// Asymmetric gate on the two new scan tables (class | |
| 15175 | + /// `reference-layout-not-spec`): a transposed pair of tables passes any | |
| 15176 | + /// "is a permutation" check, so this pins the pair AGAINST each other -- | |
| 15177 | + /// `SCAN_8X4[k]` must be `SCAN_4X8[k]` reflected across the diagonal, and | |
| 15178 | + /// both must be bijections of `0..32` in our own row-major indexing. | |
| 15179 | + #[test] | |
| 15180 | + fn the_rect_4x8_scans_are_each_other_transposed() { | |
| 15181 | + let mut seen_a = [false; 32]; | |
| 15182 | + let mut seen_b = [false; 32]; | |
| 15183 | + for k in 0..32usize { | |
| 15184 | + let a = SCAN_4X8[k] as usize; | |
| 15185 | + let b = SCAN_8X4[k] as usize; | |
| 15186 | + assert!(!seen_a[a] && !seen_b[b], "scan position {k} repeats"); | |
| 15187 | + seen_a[a] = true; | |
| 15188 | + seen_b[b] = true; | |
| 15189 | + let (row, col) = (a / 4, a % 4); | |
| 15190 | + assert_eq!(b, col * 8 + row, "SCAN_8X4[{k}] is not SCAN_4X8[{k}] transposed"); | |
| 15191 | + } | |
| 15192 | + assert!(seen_a.iter().all(|&s| s) && seen_b.iter().all(|&s| s)); | |
| 15193 | + } | |
| 15194 | + | |
| 15195 | + /// `mrow_scan_4x8`/`mcol_scan_4x8`/`mrow_scan_8x4`/`mcol_scan_8x4` | |
| 15196 | + /// (libaom `scan.c`), converted out of their column-major encoding by | |
| 15197 | + /// `(p % h) * w + p / h` -- the head of each, pinned so the rect | |
| 15198 | + /// `V_DCT`/`H_DCT` walk cannot silently transpose. | |
| 15199 | + #[test] | |
| 15200 | + fn the_rect_class1_scans_match_libaom() { | |
| 15201 | + assert_eq!( | |
| 15202 | + class_scan_table_wh(4, 8, TxClass::Vert), | |
| 15203 | + (0..32u16).collect::<Vec<_>>() | |
| 15204 | + ); | |
| 15205 | + assert_eq!( | |
| 15206 | + &class_scan_table_wh(4, 8, TxClass::Horiz)[..8], | |
| 15207 | + &[0u16, 4, 8, 12, 16, 20, 24, 28] | |
| 15208 | + ); | |
| 15209 | + assert_eq!( | |
| 15210 | + class_scan_table_wh(8, 4, TxClass::Vert), | |
| 15211 | + (0..32u16).collect::<Vec<_>>() | |
| 15212 | + ); | |
| 15213 | + assert_eq!( | |
| 15214 | + &class_scan_table_wh(8, 4, TxClass::Horiz)[..8], | |
| 15215 | + &[0u16, 8, 16, 24, 1, 9, 17, 25] | |
| 15216 | + ); | |
| 15217 | + } | |
| 15218 | + | |
| 15219 | + /// The 32-position `eob_pt` alphabet: six symbols (one more than the | |
| 15220 | + /// 16-position table, one fewer than the 64-position one), strictly | |
| 15221 | + /// increasing, terminated at 32768 with the adaptation counter after it. | |
| 15222 | + #[test] | |
| 15223 | + fn the_32_position_eob_tables_are_well_formed() { | |
| 15224 | + for table in [ | |
| 15225 | + &cdf::EOB_PT_32_LUMA_Q0, | |
| 15226 | + &cdf::EOB_PT_32_LUMA_Q1, | |
| 15227 | + &cdf::EOB_PT_32_LUMA, | |
| 15228 | + &cdf::EOB_PT_32_LUMA_Q3, | |
| 15229 | + &cdf::EOB_PT_32_LUMA_CLASS1_Q0, | |
| 15230 | + &cdf::EOB_PT_32_LUMA_CLASS1_Q1, | |
| 15231 | + &cdf::EOB_PT_32_LUMA_CLASS1, | |
| 15232 | + &cdf::EOB_PT_32_LUMA_CLASS1_Q3, | |
| 15233 | + ] { | |
| 15234 | + assert_eq!(table.len(), 7); | |
| 15235 | + assert_eq!(table[5], 32768); | |
| 15236 | + assert_eq!(table[6], 0); | |
| 15237 | + for w in table[..6].windows(2) { | |
| 15238 | + assert!(w[0] < w[1], "{table:?} is not increasing"); | |
| 15239 | + } | |
| 15240 | + } | |
| 15241 | + } | |
| 15242 | + | |
| 15243 | + /// `Reach::of_rect` must read libaom's own `has_tr_4x8`/`has_tr_8x4` | |
| 15244 | + /// rows, not the 32x16 pair the two existing rect strips use: the two | |
| 15245 | + /// shapes disagree at a position inside the superblock, which is what | |
| 15246 | + /// makes this an asymmetric check rather than a tautology. | |
| 15247 | + #[test] | |
| 15248 | + fn the_sub8_rect_reach_tables_are_shape_specific() { | |
| 15249 | + let a = Reach::of_rect(4, 8, 4, 8, 64, 64); | |
| 15250 | + let b = Reach::of_rect(8, 4, 8, 4, 64, 64); | |
| 15251 | + assert!( | |
| 15252 | + a.above_right != b.above_right || a.below_left != b.below_left, | |
| 15253 | + "4x8 and 8x4 reach identically at mirrored positions -- one table is unused" | |
| 15254 | + ); | |
| 15255 | + } | |
| 15256 | +} |
crates/ec-av1/src/encode.rsmodified+41 -2
| @@ -1078,6 +1078,45 @@ const HAS_TOP_RIGHT_RECT: [&[u8]; 2] = [&[15, 5, 7, 5], &[255, 119, 127, 119]]; | ||
| 1078 | 1078 | /// `has_bl_32x16`/`has_bl_16x32`, same source, same order. |
| 1079 | 1079 | const HAS_BOTTOM_LEFT_RECT: [&[u8]; 2] = [&[78, 14, 78, 14], &[16, 0, 16, 0]]; |
| 1080 | 1080 | |
| 1081 | +/// `has_tr_4x8` (libaom `reconintra.c`), transcribed verbatim -- lane-tx4x8's | |
| 1082 | +/// `PARTITION_VERT` leaf of an 8x8 block. Row stride is | |
| 1083 | +/// [`Reach::table_stride`]`(4)` = 32 bits, as for every other entry of | |
| 1084 | +/// libaom's own `has_tr_tables`. | |
| 1085 | +const HAS_TR_4X8: [u8; 64] = [ | |
| 1086 | + 255, 255, 255, 255, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 127, 255, | |
| 1087 | + 127, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 255, 255, 127, 119, 119, | |
| 1088 | + 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 127, 255, 127, 119, 119, 119, 119, 127, | |
| 1089 | + 127, 127, 127, 119, 119, 119, 119, | |
| 1090 | +]; | |
| 1091 | +/// `has_tr_8x4`, same source -- the `PARTITION_HORZ` leaf. | |
| 1092 | +const HAS_TR_8X4: [u8; 64] = [ | |
| 1093 | + 255, 255, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, 127, 127, 0, 0, 85, 85, 0, 0, 119, | |
| 1094 | + 119, 0, 0, 85, 85, 0, 0, 255, 127, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, 127, 127, | |
| 1095 | + 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, | |
| 1096 | +]; | |
| 1097 | +/// `has_bl_4x8`, same source. | |
| 1098 | +const HAS_BL_4X8: [u8; 64] = [ | |
| 1099 | + 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 1, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, | |
| 1100 | + 17, 0, 0, 0, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 1, 0, 16, 17, 17, 17, 0, 1, | |
| 1101 | + 1, 1, 16, 17, 17, 17, 0, 0, 0, 0, | |
| 1102 | +]; | |
| 1103 | +/// `has_bl_8x4`, same source. | |
| 1104 | +const HAS_BL_8X4: [u8; 64] = [ | |
| 1105 | + 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 1, 254, 255, 84, 85, 254, | |
| 1106 | + 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 0, 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, | |
| 1107 | + 84, 85, 254, 255, 0, 1, 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 0, | |
| 1108 | +]; | |
| 1109 | + | |
| 1110 | +/// The `has_tr_*`/`has_bl_*` row for one rectangular block shape. | |
| 1111 | +fn rect_reach_tables(bw: usize, bh: usize) -> (&'static [u8], &'static [u8]) { | |
| 1112 | + match (bw, bh) { | |
| 1113 | + (4, 8) => (&HAS_TR_4X8, &HAS_BL_4X8), | |
| 1114 | + (8, 4) => (&HAS_TR_8X4, &HAS_BL_8X4), | |
| 1115 | + (16, 32) => (HAS_TOP_RIGHT_RECT[1], HAS_BOTTOM_LEFT_RECT[1]), | |
| 1116 | + _ => (HAS_TOP_RIGHT_RECT[0], HAS_BOTTOM_LEFT_RECT[0]), | |
| 1117 | + } | |
| 1118 | +} | |
| 1119 | + | |
| 1081 | 1120 | impl Reach { |
| 1082 | 1121 | /// What a block of `side` samples at `(x, y)` may read past its own edges, |
| 1083 | 1122 | /// in a frame of `width` by `height`. |
| @@ -1124,7 +1163,7 @@ impl Reach { | ||
| 1124 | 1163 | if col + 1 == per_col { |
| 1125 | 1164 | return false; |
| 1126 | 1165 | } |
| 1127 | - let table = HAS_TOP_RIGHT_RECT[usize::from(bw == 16)]; | |
| 1166 | + let table = rect_reach_tables(bw, bh).0; | |
| 1128 | 1167 | Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8)) |
| 1129 | 1168 | } |
| 1130 | 1169 | |
| @@ -1136,7 +1175,7 @@ impl Reach { | ||
| 1136 | 1175 | if row + 1 == per_row { |
| 1137 | 1176 | return false; |
| 1138 | 1177 | } |
| 1139 | - let table = HAS_BOTTOM_LEFT_RECT[usize::from(bw == 16)]; | |
| 1178 | + let table = rect_reach_tables(bw, bh).1; | |
| 1140 | 1179 | Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8)) |
| 1141 | 1180 | } |
| 1142 | 1181 |
crates/ec-av1/src/refusal_inventory.rsmodified+0 -3
| @@ -25,10 +25,8 @@ | ||
| 25 | 25 | #[cfg(test)] |
| 26 | 26 | const CAPABILITY_CLAIMS: &[&str] = &[ |
| 27 | 27 | "filter intra on a superblock-level HORZ/VERT strip (never expected -- av1_filter_intra_allowed_bsize caps at 32x32)", |
| 28 | - "a non-2D tx class on a rectangular transform (never expected at this size)", | |
| 29 | 28 | "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", |
| 30 | 29 | "a nonzero angle delta (this encoder never writes one)", |
| 31 | - "a tx_type symbol on a rectangular transform (never expected at this size)", | |
| 32 | 30 | ]; |
| 33 | 31 | |
| 34 | 32 | #[cfg(test)] |
| @@ -37,7 +35,6 @@ const REFUSALS: &[&str] = &[ | ||
| 37 | 35 | "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only the skip case at this size)", |
| 38 | 36 | "a coded (non-skip) HORZ/VERT rect strip below 16x16 (this decoder ports only the skip case at this size)", |
| 39 | 37 | "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)", |
| 40 | - "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)", | |
| 41 | 38 | "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", |
| 42 | 39 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| 43 | 40 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
crates/ec-av1/src/stream.rsmodified+201 -0
| @@ -7413,6 +7413,207 @@ mod tests { | ||
| 7413 | 7413 | } |
| 7414 | 7414 | } |
| 7415 | 7415 | |
| 7416 | + /// lane-tx4x8: `--enable-rect-partitions=1` with `--min-partition-size=4 | |
| 7417 | + /// --max-partition-size=8` on fine-detail noisy gradients makes aomenc | |
| 7418 | + /// pick `PARTITION_VERT`/`PARTITION_HORZ` at the 8x8 level -- two | |
| 7419 | + /// `BLOCK_4X8`/`BLOCK_8X4` leaves, the last sub-8x8 shape this decoder | |
| 7420 | + /// refused (it needed a real `TX_4X8`/`TX_8X4`: rect scan, 32-position | |
| 7421 | + /// `eob_pt`, `TX_4X4` `tx_type` row over `TX_8X8` coefficient tables). | |
| 7422 | + /// Both [`decode::tx4x8_coded_hits`] and [`decode::tx8x4_coded_hits`] are | |
| 7423 | + /// hard-asserted per firing attempt so neither orientation can ride along | |
| 7424 | + /// on the other ([[gate-blind-to-feature]]), and only leaves that coded | |
| 7425 | + /// REAL coefficients count -- a skipped leaf never runs the transform. | |
| 7426 | + /// Arms: 8-bit 64x64, an 8-bit `--tile-columns=1` 128x64 (the mi-granular | |
| 7427 | + /// mode maps are per tile), and a 10-bit 64x64. | |
| 7428 | + #[test] | |
| 7429 | + fn a_real_aomenc_stream_with_a_sub8_rect_leaf_decodes_pixel_exact() { | |
| 7430 | + const NAME: &str = "a_real_aomenc_stream_with_a_sub8_rect_leaf_decodes_pixel_exact"; | |
| 7431 | + if !have_ffmpeg() { | |
| 7432 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 7433 | + return; | |
| 7434 | + } | |
| 7435 | + if !have_aomenc() { | |
| 7436 | + let msg = format!("no aomenc at {}", aomenc_path().display()); | |
| 7437 | + assert!( | |
| 7438 | + std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(), | |
| 7439 | + "EC_AV1_REQUIRE_AOMENC is set but {msg}" | |
| 7440 | + ); | |
| 7441 | + eprintln!("SKIP {NAME}: {msg}"); | |
| 7442 | + return; | |
| 7443 | + } | |
| 7444 | + // 16-pixel-tall/wide fixtures on purpose: at 64x64 EVERY attempt | |
| 7445 | + // dies on a 16x16-LEVEL rect refusal belonging to other lanes | |
| 7446 | + // ("a HORZ/VERT intra strip with a split transform", "a coded | |
| 7447 | + // (non-skip) HORZ/VERT rect strip below 16x16", "a HORZ_A/HORZ_B/ | |
| 7448 | + // VERT_A partition below 16x16") -- `--max-partition-size=8` does | |
| 7449 | + // NOT stop aomenc coding a 16x16 as two 16x8 strips, measured | |
| 7450 | + // 39/40 attempts refused. A 16x16 frame is one 16x16 block, so the | |
| 7451 | + // encoder either splits it to 8x8s (this lane's path) or codes it | |
| 7452 | + // whole; measured 12/12 attempts decoding, 3/12 with BOTH | |
| 7453 | + // orientations coded. | |
| 7454 | + for (width, height, tile_args, bit_depth) in [ | |
| 7455 | + (16usize, 16usize, &[][..], 8u8), | |
| 7456 | + (128usize, 16usize, &["--tile-columns=1"][..], 8u8), | |
| 7457 | + (16usize, 16usize, &[][..], 10u8), | |
| 7458 | + ] { | |
| 7459 | + let mut refusals = Vec::new(); | |
| 7460 | + let mut fired_runs = 0u32; | |
| 7461 | + for attempt in 0..40u32 { | |
| 7462 | + let seed = 300 + attempt; | |
| 7463 | + let cq = 6 + (attempt % 4) * 2; | |
| 7464 | + let pix_fmt = if bit_depth == 10 { | |
| 7465 | + "yuv420p10le" | |
| 7466 | + } else { | |
| 7467 | + "yuv420p" | |
| 7468 | + }; | |
| 7469 | + let y4m = Command::new("ffmpeg") | |
| 7470 | + .args([ | |
| 7471 | + "-v", | |
| 7472 | + "error", | |
| 7473 | + "-f", | |
| 7474 | + "lavfi", | |
| 7475 | + "-i", | |
| 7476 | + &format!("testsrc2=size={width}x{height}:rate=25"), | |
| 7477 | + "-vf", | |
| 7478 | + &format!("noise=alls=40:allf=t:all_seed={seed},format={pix_fmt}"), | |
| 7479 | + "-strict", | |
| 7480 | + "-1", | |
| 7481 | + "-t", | |
| 7482 | + "0.04", | |
| 7483 | + "-f", | |
| 7484 | + "yuv4mpegpipe", | |
| 7485 | + "-", | |
| 7486 | + ]) | |
| 7487 | + .stdin(Stdio::null()) | |
| 7488 | + .stdout(Stdio::piped()) | |
| 7489 | + .stderr(Stdio::piped()) | |
| 7490 | + .output() | |
| 7491 | + .expect("ffmpeg failed to run"); | |
| 7492 | + assert!( | |
| 7493 | + y4m.status.success(), | |
| 7494 | + "ffmpeg fixture: {}", | |
| 7495 | + String::from_utf8_lossy(&y4m.stderr) | |
| 7496 | + ); | |
| 7497 | + let mut child = Command::new(aomenc_path()) | |
| 7498 | + .args([ | |
| 7499 | + "--codec=av1", | |
| 7500 | + "--passes=1", | |
| 7501 | + "--end-usage=q", | |
| 7502 | + &format!("--cq-level={cq}"), | |
| 7503 | + "--cpu-used=0", | |
| 7504 | + "--threads=1", | |
| 7505 | + "--row-mt=0", | |
| 7506 | + "--sb-size=64", | |
| 7507 | + "--min-partition-size=4", | |
| 7508 | + "--max-partition-size=8", | |
| 7509 | + // The tool under test: rect partitions ON, at a size | |
| 7510 | + // where the only rect shapes are 4x8 and 8x4. | |
| 7511 | + "--enable-rect-partitions=1", | |
| 7512 | + "--enable-ab-partitions=0", | |
| 7513 | + "--enable-1to4-partitions=0", | |
| 7514 | + "--enable-palette=0", | |
| 7515 | + "--enable-intrabc=0", | |
| 7516 | + "--enable-restoration=0", | |
| 7517 | + "--enable-cdef=0", | |
| 7518 | + "--loopfilter-control=0", | |
| 7519 | + "--enable-ref-frame-mvs=0", | |
| 7520 | + // Filter intra on a 4x8/8x4 leaf is refused by name | |
| 7521 | + // (`predict_filter_intra` is square-only in this | |
| 7522 | + // decoder, the same refusal the 16x16-level strips | |
| 7523 | + // carry); with it on, that refusal -- not this | |
| 7524 | + // lane's path -- is what most attempts hit. | |
| 7525 | + "--enable-filter-intra=0", | |
| 7526 | + "--limit=1", | |
| 7527 | + "--obu", | |
| 7528 | + "-o", | |
| 7529 | + "-", | |
| 7530 | + "-", | |
| 7531 | + ]) | |
| 7532 | + .args(if bit_depth == 10 { | |
| 7533 | + &["--input-bit-depth=10", "--bit-depth=10"][..] | |
| 7534 | + } else { | |
| 7535 | + &[][..] | |
| 7536 | + }) | |
| 7537 | + .args(tile_args) | |
| 7538 | + .stdin(Stdio::piped()) | |
| 7539 | + .stdout(Stdio::piped()) | |
| 7540 | + .stderr(Stdio::piped()) | |
| 7541 | + .spawn() | |
| 7542 | + .expect("aomenc failed to start"); | |
| 7543 | + child | |
| 7544 | + .stdin | |
| 7545 | + .take() | |
| 7546 | + .expect("aomenc stdin") | |
| 7547 | + .write_all(&y4m.stdout) | |
| 7548 | + .expect("writing y4m to aomenc"); | |
| 7549 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 7550 | + if !out.status.success() { | |
| 7551 | + refusals.push(format!( | |
| 7552 | + "seed={seed} cq={cq}: aomenc itself refused the fixture" | |
| 7553 | + )); | |
| 7554 | + continue; | |
| 7555 | + } | |
| 7556 | + let stream = out.stdout; | |
| 7557 | + let vert_before = decode::tx4x8_coded_hits(); | |
| 7558 | + let horz_before = decode::tx8x4_coded_hits(); | |
| 7559 | + let tiles_before = decode::tile_hits(); | |
| 7560 | + let frames = match decode_stream(&stream) { | |
| 7561 | + Ok(frames) => frames, | |
| 7562 | + Err(e) => { | |
| 7563 | + let msg = e.to_string(); | |
| 7564 | + assert!( | |
| 7565 | + msg.starts_with("unsupported: "), | |
| 7566 | + "decode error that is not a named refusal \ | |
| 7567 | + (seed={seed} cq={cq} depth={bit_depth} tiles={tile_args:?}): {msg}" | |
| 7568 | + ); | |
| 7569 | + refusals.push(format!("seed={seed} cq={cq}: {msg}")); | |
| 7570 | + continue; | |
| 7571 | + } | |
| 7572 | + }; | |
| 7573 | + assert!( | |
| 7574 | + tile_args.is_empty() || decode::tile_hits() - tiles_before >= 2, | |
| 7575 | + "tiles={tile_args:?} decoded only {} tile(s) (seed={seed} cq={cq})", | |
| 7576 | + decode::tile_hits() - tiles_before | |
| 7577 | + ); | |
| 7578 | + let vert = decode::tx4x8_coded_hits() - vert_before; | |
| 7579 | + let horz = decode::tx8x4_coded_hits() - horz_before; | |
| 7580 | + if vert == 0 || horz == 0 { | |
| 7581 | + refusals.push(format!( | |
| 7582 | + "seed={seed} cq={cq}: decoded, but coded 4x8={vert} 8x4={horz} leaves" | |
| 7583 | + )); | |
| 7584 | + continue; | |
| 7585 | + } | |
| 7586 | + let ffmpeg_frames = if bit_depth == 10 { | |
| 7587 | + ffmpeg_decode_sequence_10bit(&stream, width, height, 1) | |
| 7588 | + } else { | |
| 7589 | + ffmpeg_decode_sequence(&stream, width, height, 1) | |
| 7590 | + }; | |
| 7591 | + assert_eq!( | |
| 7592 | + frames[0].y, ffmpeg_frames[0].y, | |
| 7593 | + "luma vs ffmpeg (seed={seed} cq={cq} depth={bit_depth} tiles={tile_args:?})" | |
| 7594 | + ); | |
| 7595 | + assert_eq!( | |
| 7596 | + frames[0].u, ffmpeg_frames[0].u, | |
| 7597 | + "U vs ffmpeg (seed={seed} cq={cq} depth={bit_depth})" | |
| 7598 | + ); | |
| 7599 | + assert_eq!( | |
| 7600 | + frames[0].v, ffmpeg_frames[0].v, | |
| 7601 | + "V vs ffmpeg (seed={seed} cq={cq} depth={bit_depth})" | |
| 7602 | + ); | |
| 7603 | + fired_runs += 1; | |
| 7604 | + if fired_runs >= 4 { | |
| 7605 | + break; | |
| 7606 | + } | |
| 7607 | + } | |
| 7608 | + assert!( | |
| 7609 | + fired_runs >= 4, | |
| 7610 | + "fewer than 4 firing+pixel-exact runs out of 40 attempts \ | |
| 7611 | + ({width}x{height} depth={bit_depth} tiles={tile_args:?}):\n{}", | |
| 7612 | + refusals.join("\n") | |
| 7613 | + ); | |
| 7614 | + } | |
| 7615 | + } | |
| 7616 | + | |
| 7416 | 7617 | /// lane-av1golden7 r9's decisive fixture: a real aomenc stream (seed 59, |
| 7417 | 7618 | /// `--tune-content=film`, GOLDEN_FRAME firing downstream) whose frame-0 |
| 7418 | 7619 | /// *intra keyframe* mismatched ffmpeg on 3855/4096 luma pixels -- traced |
lanes/tx4x8-r1.report.mdadded+92 -0
| @@ -0,0 +1,92 @@ | ||
| 1 | +# lane-tx4x8 round 1 — TX_4X8/TX_8X4 end to end (gate RED, first divergence not yet isolated) | |
| 2 | + | |
| 3 | +Branch `lane-tx4x8` off `lane-sub8` b500160. NOT rebased onto main (charter order). | |
| 4 | + | |
| 5 | +## What changed | |
| 6 | + | |
| 7 | +* `crates/ec-av1/src/cdf.rs` — `EOB_PT_32_LUMA{,_Q0,_Q1,_Q3}` + `_CLASS1` siblings, | |
| 8 | + transcribed from `av1_default_eob_multi32_cdfs` (`token_cdfs.h:792`), luma plane, both | |
| 9 | + tx-class rows. Format cross-checked against the already-pinned `EOB_PT_16_LUMA_CLASS1_Q0`. | |
| 10 | +* `crates/ec-av1/src/cdf_state.rs` — `eob_pt_32_luma{,_class1}` state + q-ctx `pick` + counter | |
| 11 | + reset; `TxbSet::LumaRect4x8`/`LumaRect4x8Set1`. Derivation: `get_txsize_entropy_ctx(TX_4X8)` | |
| 12 | + = `(txsize_sqr_map=TX_4X4 + txsize_sqr_up_map=TX_8X8 + 1) >> 1` = **TX_8X8**, so every | |
| 13 | + coefficient table is `Luma8`'s; `read_tx_type`'s CDF row is `txsize_sqr_map[TX_4X8]` = | |
| 14 | + **TX_4X4**, so the `tx_type` table is `Luma4`/`Luma4Set1`'s; `eob_pt` is the true | |
| 15 | + 32-position table (`txsize_log2_minus4[TX_4X8] == 1` -> `eob_flag_cdf32`). | |
| 16 | + (class `table-indexed-by-raw-size`: three different size keys in one variant.) | |
| 17 | +* `crates/ec-av1/src/decode.rs` — | |
| 18 | + - `SCAN_4X8`/`SCAN_8X4` (libaom `default_scan_4x8`/`8x4`), `class_scan_table_wh` | |
| 19 | + (`mrow`/`mcol` at rect sizes). Conversion `(p % h) * w + p / h` **re-proved first** by | |
| 20 | + regenerating the committed `SCAN_16X8`/`SCAN_8X16` from the same source (heads matched). | |
| 21 | + - `base_ctx_rect`/`br_ctx_rect` gained a `TxClass` (the 1D-class arms are shape-independent | |
| 22 | + in libaom's `get_nz_map_ctx_from_stats`; no new `av1_nz_map_ctx_offset_*` table is needed — | |
| 23 | + the `w<h -> 11+ctx` / `w>h -> 16+ctx` rule already in `base_ctx_rect` IS that table). | |
| 24 | + - `read_coeffs_rect` now reads a real `tx_type` symbol and honours `V_DCT`/`H_DCT` | |
| 25 | + (rect class scan + class contexts + `eob_pt_class1`). Two capability-claim refusals | |
| 26 | + deleted. | |
| 27 | + - `decode_leaf_rect8` — the `PARTITION_HORZ`/`VERT` leaf of an 8x8: two `BLOCK_8X4`/`4X8` | |
| 28 | + sub-blocks, mode reads via `read_intra_mode_sub8`, chroma once on the last sub-block at the | |
| 29 | + group's 4x4 unit, `dequant_and_inverse_typed_wh` (the rect transform primitive, its | |
| 30 | + `abs(rect_type)==1` `NewInvSqrt2` scale and `av1_inv_txfm_shift_ls[TX_4X8]` row, already | |
| 31 | + existed and needed no change), `Reach::of_rect`, `fill_lf_grid_rect(bw, bh)` for the | |
| 32 | + deblock grid, `partition_context_lookup[BLOCK_4X8] = {31,30}` / `[BLOCK_8X4] = {30,31}`. | |
| 33 | + Wired at BOTH sub-8x8 partition sites; the leftover `else` is now `unreachable!` | |
| 34 | + (`partition_w8` is a 4-symbol CDF). | |
| 35 | + - counters `tx4x8_coded_hits`/`tx8x4_coded_hits` (leaves with REAL coefficients only). | |
| 36 | + - 4 new table tests (transposed-pair scan gate, class-1 scan pins, eob table shape, | |
| 37 | + shape-specific reach). | |
| 38 | +* `crates/ec-av1/src/encode.rs` — `has_tr_4x8`/`has_tr_8x4`/`has_bl_4x8`/`has_bl_8x4` | |
| 39 | + transcribed verbatim; `rect_reach_tables(bw, bh)` replaces the `bw == 16` two-way pick. | |
| 40 | +* `crates/ec-av1/src/refusal_inventory.rs` — three refusals removed: the 4x8/8x4 partition | |
| 41 | + refusal and the two rect `tx_type`/`tx class` capability claims. | |
| 42 | +* `crates/ec-av1/src/stream.rs` — gate | |
| 43 | + `a_real_aomenc_stream_with_a_sub8_rect_leaf_decodes_pixel_exact`, three arms | |
| 44 | + (8-bit 16x16, 8-bit 128x16 `--tile-columns=1`, 10-bit 16x16), `--enable-rect-partitions=1 | |
| 45 | + --min-partition-size=4 --max-partition-size=8`, per-attempt hard assert that BOTH | |
| 46 | + `tx4x8_coded_hits` and `tx8x4_coded_hits` moved, named refusals only, no SKIP on error. | |
| 47 | + | |
| 48 | +## Gate: RED | |
| 49 | + | |
| 50 | +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib sub8_rect_leaf` | |
| 51 | +-> `luma vs ffmpeg (seed=303 cq=12 depth=8 tiles=[])`, mismatch from sample 0 of a 16x16 | |
| 52 | +frame; ours is near-flat (126..142), ffmpeg's is full-range (0..229). The decode does not | |
| 53 | +error, so this is wrong coefficients/reconstruction (or an entropy divergence inside the | |
| 54 | +first rect leaf), not a refusal. | |
| 55 | + | |
| 56 | +EVIDENCE: cargo test output above | 40 attempts x 3 arms, aomenc --enable-rect-partitions=1 | |
| 57 | +--min-partition-size=4 --max-partition-size=8 --enable-filter-intra=0 on testsrc2+noise 16x16 | | |
| 58 | +first firing attempt (seed 303) mismatches luma at index 0; 291 other lib tests unaffected at | |
| 59 | +the time of the run. | |
| 60 | + | |
| 61 | +EVIDENCE: probe sweep with examples/decode_probe + EC_AV1_TRACE=1 | 12 seeds x 16x16, 12 x | |
| 62 | +32x32, --enable-filter-intra=0 | 16x16: 12/12 decode without any refusal, 3/12 code BOTH | |
| 63 | +orientations, 9/12 at least one; 32x32: 1/12 (11 die on 16x16-LEVEL rect refusals owned by | |
| 64 | +other lanes) — this is why the gate uses 16x16/128x16 fixtures. | |
| 65 | + | |
| 66 | +## Recipe findings (cite before reusing) | |
| 67 | + | |
| 68 | +* `--max-partition-size=8` does NOT stop aomenc coding a 16x16 block as two 16x8 strips: at | |
| 69 | + 64x64, 39/40 attempts refuse on 16x16-level rect gaps ("a HORZ/VERT intra strip with a split | |
| 70 | + transform", "a coded (non-skip) HORZ/VERT rect strip below 16x16", "a HORZ_A/HORZ_B/VERT_A | |
| 71 | + partition below 16x16"). Only a 16-pixel frame dimension isolates the 8x8 level. | |
| 72 | +* With `--enable-filter-intra=1`, most attempts die on the pre-existing square-only filter-intra | |
| 73 | + refusal, which `decode_leaf_rect8` re-raises by name for a 4x8 leaf. | |
| 74 | +* A probe sweep whose binary path was wrong reported "OK, 0 hits" for every cell | |
| 75 | + (class `stale-output-faked-measurement`): always `ls -l` the probe binary in the lane's own | |
| 76 | + `CARGO_TARGET_DIR` first. The first sweep in this round was invalid for exactly that reason. | |
| 77 | + | |
| 78 | +## Residue | |
| 79 | + | |
| 80 | +* fix-now (next round): the pixel mismatch. Nothing in the ladder below was disproved this | |
| 81 | + round, ranked by suspicion: | |
| 82 | + 1. an entropy divergence at the FIRST rect leaf (range ladder vs instrumented aomdec, | |
| 83 | + `EC_TRACE_COEFF`, on the pinned seed-303 stream) — ours decoding a near-flat frame is | |
| 84 | + consistent with an `eob`/`all_zero` read off the wrong table; | |
| 85 | + 2. `TxbSet::LumaRect4x8`'s three-way table split (coeff tables TX_8X8 / tx_type row TX_4X4 / | |
| 86 | + eob 32) — verify each against `read_coeffs_txb` live, not against my derivation; | |
| 87 | + 3. `dequant_wh` / the rect transform at (4,8) — never exercised below 16x8 before this lane; | |
| 88 | + 4. `Reach::of_rect` at 4x8/8x4 (localized errors only — would not explain sample 0). | |
| 89 | +* deferred: `--tile-columns=1` arm result — not separable while arm 1 is red — unblocked by | |
| 90 | + the fix above. | |
| 91 | +* deferred: filter intra on a 4x8/8x4 leaf — `predict_filter_intra` is square-only — unblocked | |
| 92 | + by a rect filter-intra predictor (same refusal the 16x16-level strips carry). |