wip(txselect): session restart -- uncommitted builder state preserved by orchestrator
Browse files at this commitd47ed6547a7c2b9efed0271fc080ccb0f03c76c3Parent: d21774e3 changed files +584 -41
- crates/ec-av1/src/cdf.rs +41 -0
- crates/ec-av1/src/cdf_state.rs +49 -0
- crates/ec-av1/src/decode.rs +494 -41
crates/ec-av1/src/cdf.rsmodified+41 -0
| @@ -25,6 +25,33 @@ pub const PARTITION_W64: [[u16; 11]; 4] = [ | |||
| 25 | 25 | ||
| 26 | /// `Default_Skip_Cdf` (spec 9.4): indexed by how many of the blocks above | 26 | /// `Default_Skip_Cdf` (spec 9.4): indexed by how many of the blocks above |
| 27 | /// and left were skipped. | 27 | /// and left were skipped. |
| 28 | +/// `default_txfm_partition_cdf` (entropymode.c): an inter block's | ||
| 29 | +/// `txfm_split` flag (spec 5.11.17 `read_var_tx_size`), indexed by | ||
| 30 | +/// `txfm_partition_context` -- `category * 3 + above + left`, 21 contexts. | ||
| 31 | +pub const TXFM_PARTITION: [[u16; 3]; 21] = [ | ||
| 32 | + [28581, 32768, 0], | ||
| 33 | + [23846, 32768, 0], | ||
| 34 | + [20847, 32768, 0], | ||
| 35 | + [24315, 32768, 0], | ||
| 36 | + [18196, 32768, 0], | ||
| 37 | + [12133, 32768, 0], | ||
| 38 | + [18791, 32768, 0], | ||
| 39 | + [10887, 32768, 0], | ||
| 40 | + [11005, 32768, 0], | ||
| 41 | + [27179, 32768, 0], | ||
| 42 | + [20004, 32768, 0], | ||
| 43 | + [11281, 32768, 0], | ||
| 44 | + [26549, 32768, 0], | ||
| 45 | + [19308, 32768, 0], | ||
| 46 | + [14224, 32768, 0], | ||
| 47 | + [28015, 32768, 0], | ||
| 48 | + [21546, 32768, 0], | ||
| 49 | + [14400, 32768, 0], | ||
| 50 | + [28165, 32768, 0], | ||
| 51 | + [22401, 32768, 0], | ||
| 52 | + [16088, 32768, 0], | ||
| 53 | +]; | ||
| 54 | + | ||
| 28 | pub const SKIP: [[u16; 3]; 3] = [[31671, 32768, 0], [16515, 32768, 0], [4576, 32768, 0]]; | 55 | pub const SKIP: [[u16; 3]; 3] = [[31671, 32768, 0], [16515, 32768, 0], [4576, 32768, 0]]; |
| 29 | 56 | ||
| 30 | /// `Default_Intra_Frame_Y_Mode_Cdf` (spec 9.4): the thirteen luma intra | 57 | /// `Default_Intra_Frame_Y_Mode_Cdf` (spec 9.4): the thirteen luma intra |
| @@ -1381,6 +1408,20 @@ pub const INTER_TX_TYPE_SET2_16: [u16; 13] = [ | |||
| 1381 | 770, 2421, 5225, 12907, 15819, 18927, 21561, 24089, 26595, 28526, 30529, 32768, 0, | 1408 | 770, 2421, 5225, 12907, 15819, 18927, 21561, 24089, 26595, 28526, 30529, 32768, 0, |
| 1382 | ]; | 1409 | ]; |
| 1383 | 1410 | ||
| 1411 | +/// `Default_Inter_Ext_Tx_Cdf`'s `TX_SET_INTER_1` (`EXT_TX_SET_ALL16`) row for | ||
| 1412 | +/// `TX_4X4` (lane-txselect): the sixteen-symbol transform type of an | ||
| 1413 | +/// `is_inter` 4x4 luma transform when `reduced_tx_set == 0` (libaom | ||
| 1414 | +/// `entropymode.c` `default_inter_ext_tx_cdf[1][TX_4X4]`). | ||
| 1415 | +pub const INTER_TX_TYPE_SET1_4: [u16; 17] = [ | ||
| 1416 | + 4458, 5560, 7695, 9709, 13330, 14789, 17537, 20266, 21504, 22848, 23934, 25474, 27727, 28915, | ||
| 1417 | + 30631, 32768, 0, | ||
| 1418 | +]; | ||
| 1419 | + | ||
| 1420 | +/// `Default_Inter_Ext_Tx_Cdf`'s `TX_SET_INTER_3` (`EXT_TX_SET_DCT_IDTX`) row | ||
| 1421 | +/// for `TX_4X4` (lane-txselect), the reduced two-symbol counterpart of | ||
| 1422 | +/// [`INTER_TX_TYPE_SET1_4`] (`default_inter_ext_tx_cdf[3][TX_4X4]`). | ||
| 1423 | +pub const INTER_TX_TYPE_SET3_4: [u16; 3] = [16384, 32768, 0]; | ||
| 1424 | + | ||
| 1384 | /// `Default_Inter_Ext_Tx_Cdf`'s `TX_SET_INTER_1` (`EXT_TX_SET_ALL16`) row for | 1425 | /// `Default_Inter_Ext_Tx_Cdf`'s `TX_SET_INTER_1` (`EXT_TX_SET_ALL16`) row for |
| 1385 | /// `TX_8X8` (lane-cdffwd2): the full sixteen-symbol transform type of an | 1426 | /// `TX_8X8` (lane-cdffwd2): the full sixteen-symbol transform type of an |
| 1386 | /// `is_inter` 8x8 luma transform when `reduced_tx_set == 0` | 1427 | /// `is_inter` 8x8 luma transform when `reduced_tx_set == 0` |
crates/ec-av1/src/cdf_state.rsmodified+49 -0
| @@ -71,6 +71,16 @@ pub(crate) enum TxbSet { | |||
| 71 | /// `is_inter` block has no writer path yet, so this crate has no | 71 | /// `is_inter` block has no writer path yet, so this crate has no |
| 72 | /// `Luma4Inter` counterpart to [`Luma8Inter`](TxbSet::Luma8Inter). | 72 | /// `Luma4Inter` counterpart to [`Luma8Inter`](TxbSet::Luma8Inter). |
| 73 | Luma4, | 73 | Luma4, |
| 74 | + /// The 4x4 luma transform of an `is_inter` block whose `TxMode::Select` | ||
| 75 | + /// var-tx tree splits an 8x8 unit all the way down (lane-txselect): the | ||
| 76 | + /// same coefficient tables [`Luma4`](TxbSet::Luma4) reads (libaom's | ||
| 77 | + /// coefficient CDFs are keyed by plane type, not intra/inter), with the | ||
| 78 | + /// inter `tx_type` set in place of the intra one. | ||
| 79 | + Luma4Inter, | ||
| 80 | + /// [`Luma4Inter`](TxbSet::Luma4Inter)'s `reduced_tx_set: false` | ||
| 81 | + /// counterpart -- the sixteen-symbol `EXT_TX_SET_ALL16` table | ||
| 82 | + /// ([`crate::cdf::INTER_TX_TYPE_SET1_4`]). | ||
| 83 | + Luma4InterSet1, | ||
| 74 | /// [`Luma4`](TxbSet::Luma4)'s `reduced_tx_set: false` counterpart, same | 84 | /// [`Luma4`](TxbSet::Luma4)'s `reduced_tx_set: false` counterpart, same |
| 75 | /// split as [`Luma8Set1`](TxbSet::Luma8Set1). | 85 | /// split as [`Luma8Set1`](TxbSet::Luma8Set1). |
| 76 | Luma4Set1, | 86 | Luma4Set1, |
| @@ -158,6 +168,10 @@ pub(crate) struct Cdfs { | |||
| 158 | /// The partition symbol of a 32x32 block. | 168 | /// The partition symbol of a 32x32 block. |
| 159 | pub partition_w32: [[u16; 11]; 4], | 169 | pub partition_w32: [[u16; 11]; 4], |
| 160 | /// Whether a block carries no residual at all. | 170 | /// Whether a block carries no residual at all. |
| 171 | + /// `txfm_partition_cdf`: an inter block's `txfm_split` flag under | ||
| 172 | + /// `TxMode::Select` (lane-txselect, spec 5.11.17), indexed by | ||
| 173 | + /// `txfm_partition_context` -- see [`cdf::TXFM_PARTITION`]. | ||
| 174 | + pub txfm_partition: [[u16; 3]; 21], | ||
| 161 | pub skip: [[u16; 3]; 3], | 175 | pub skip: [[u16; 3]; 3], |
| 162 | /// The luma mode of a key frame's block, under the two neighbours' modes. | 176 | /// The luma mode of a key frame's block, under the two neighbours' modes. |
| 163 | pub kf_y_mode: [[[u16; 14]; 5]; 5], | 177 | pub kf_y_mode: [[[u16; 14]; 5]; 5], |
| @@ -342,6 +356,11 @@ pub(crate) struct Cdfs { | |||
| 342 | /// (lane-cdffwd2): the sixteen-symbol `EXT_TX_SET_ALL16` row, not | 356 | /// (lane-cdffwd2): the sixteen-symbol `EXT_TX_SET_ALL16` row, not |
| 343 | /// indexed by mode. | 357 | /// indexed by mode. |
| 344 | pub inter_tx_type_8_set1: [u16; 17], | 358 | pub inter_tx_type_8_set1: [u16; 17], |
| 359 | + /// The 4x4 counterparts of [`Self::inter_tx_type_8`]/ | ||
| 360 | + /// [`Self::inter_tx_type_8_set1`] (lane-txselect). | ||
| 361 | + pub inter_tx_type_4: [u16; 3], | ||
| 362 | + /// See [`Self::inter_tx_type_4`]. | ||
| 363 | + pub inter_tx_type_4_set1: [u16; 17], | ||
| 345 | /// The DC sign of a chroma coefficient, shared by both chroma sets. | 364 | /// The DC sign of a chroma coefficient, shared by both chroma sets. |
| 346 | pub dc_sign_chroma: [[u16; 3]; 3], | 365 | pub dc_sign_chroma: [[u16; 3]; 3], |
| 347 | /// Whether an inter frame's block is coded as intra. | 366 | /// Whether an inter frame's block is coded as intra. |
| @@ -573,6 +592,7 @@ impl Cdfs { | |||
| 573 | pub(crate) fn reset_counts(&mut self) { | 592 | pub(crate) fn reset_counts(&mut self) { |
| 574 | reset2(&mut self.partition_w64); | 593 | reset2(&mut self.partition_w64); |
| 575 | reset2(&mut self.partition_w32); | 594 | reset2(&mut self.partition_w32); |
| 595 | + reset2(&mut self.txfm_partition); | ||
| 576 | reset2(&mut self.skip); | 596 | reset2(&mut self.skip); |
| 577 | reset3(&mut self.kf_y_mode); | 597 | reset3(&mut self.kf_y_mode); |
| 578 | reset2(&mut self.uv_mode_no_cfl); | 598 | reset2(&mut self.uv_mode_no_cfl); |
| @@ -650,6 +670,8 @@ impl Cdfs { | |||
| 650 | reset1(&mut self.inter_tx_type_8); | 670 | reset1(&mut self.inter_tx_type_8); |
| 651 | reset1(&mut self.inter_tx_type_16_set2); | 671 | reset1(&mut self.inter_tx_type_16_set2); |
| 652 | reset1(&mut self.inter_tx_type_8_set1); | 672 | reset1(&mut self.inter_tx_type_8_set1); |
| 673 | + reset1(&mut self.inter_tx_type_4); | ||
| 674 | + reset1(&mut self.inter_tx_type_4_set1); | ||
| 653 | reset2(&mut self.dc_sign_chroma); | 675 | reset2(&mut self.dc_sign_chroma); |
| 654 | reset2(&mut self.intra_inter); | 676 | reset2(&mut self.intra_inter); |
| 655 | reset3(&mut self.single_ref); | 677 | reset3(&mut self.single_ref); |
| @@ -1129,6 +1151,8 @@ impl Cdfs { | |||
| 1129 | inter_tx_type_8: cdf::INTER_TX_TYPE_SET3_8, | 1151 | inter_tx_type_8: cdf::INTER_TX_TYPE_SET3_8, |
| 1130 | inter_tx_type_16_set2: cdf::INTER_TX_TYPE_SET2_16, | 1152 | inter_tx_type_16_set2: cdf::INTER_TX_TYPE_SET2_16, |
| 1131 | inter_tx_type_8_set1: cdf::INTER_TX_TYPE_SET1_8, | 1153 | inter_tx_type_8_set1: cdf::INTER_TX_TYPE_SET1_8, |
| 1154 | + inter_tx_type_4: cdf::INTER_TX_TYPE_SET3_4, | ||
| 1155 | + inter_tx_type_4_set1: cdf::INTER_TX_TYPE_SET1_4, | ||
| 1132 | dc_sign_chroma: cdf::DC_SIGN_CHROMA, | 1156 | dc_sign_chroma: cdf::DC_SIGN_CHROMA, |
| 1133 | intra_inter: cdf::INTRA_INTER, | 1157 | intra_inter: cdf::INTRA_INTER, |
| 1134 | single_ref: cdf::SINGLE_REF, | 1158 | single_ref: cdf::SINGLE_REF, |
| @@ -1138,6 +1162,7 @@ impl Cdfs { | |||
| 1138 | uni_comp_ref: cdf::UNI_COMP_REF, | 1162 | uni_comp_ref: cdf::UNI_COMP_REF, |
| 1139 | comp_ref: cdf::COMP_REF, | 1163 | comp_ref: cdf::COMP_REF, |
| 1140 | comp_bwdref: cdf::COMP_BWDREF, | 1164 | comp_bwdref: cdf::COMP_BWDREF, |
| 1165 | + txfm_partition: cdf::TXFM_PARTITION, | ||
| 1141 | skip_mode: cdf::SKIP_MODE, | 1166 | skip_mode: cdf::SKIP_MODE, |
| 1142 | obmc: cdf::OBMC, | 1167 | obmc: cdf::OBMC, |
| 1143 | motion_mode: cdf::MOTION_MODE, | 1168 | motion_mode: cdf::MOTION_MODE, |
| @@ -1301,6 +1326,30 @@ impl Cdfs { | |||
| 1301 | tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()), | 1326 | tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()), |
| 1302 | eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1), | 1327 | eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1), |
| 1303 | }, | 1328 | }, |
| 1329 | + TxbSet::Luma4Inter => TxbTables { | ||
| 1330 | + side: 4, | ||
| 1331 | + txb_skip: &mut self.txb_skip_luma_4, | ||
| 1332 | + eob_pt: &mut self.eob_pt_16_luma, | ||
| 1333 | + eob_extra: &mut self.eob_extra_luma_4, | ||
| 1334 | + base: &mut self.base_luma_4, | ||
| 1335 | + base_eob: &mut self.base_eob_luma_4, | ||
| 1336 | + br: &mut self.br_luma_4, | ||
| 1337 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1338 | + tx_type: Some(self.inter_tx_type_4.as_mut_slice()), | ||
| 1339 | + eob_pt_class1: None, | ||
| 1340 | + }, | ||
| 1341 | + TxbSet::Luma4InterSet1 => TxbTables { | ||
| 1342 | + side: 4, | ||
| 1343 | + txb_skip: &mut self.txb_skip_luma_4, | ||
| 1344 | + eob_pt: &mut self.eob_pt_16_luma, | ||
| 1345 | + eob_extra: &mut self.eob_extra_luma_4, | ||
| 1346 | + base: &mut self.base_luma_4, | ||
| 1347 | + base_eob: &mut self.base_eob_luma_4, | ||
| 1348 | + br: &mut self.br_luma_4, | ||
| 1349 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1350 | + tx_type: Some(self.inter_tx_type_4_set1.as_mut_slice()), | ||
| 1351 | + eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1), | ||
| 1352 | + }, | ||
| 1304 | TxbSet::Luma4Set1 => TxbTables { | 1353 | TxbSet::Luma4Set1 => TxbTables { |
| 1305 | side: 4, | 1354 | side: 4, |
| 1306 | txb_skip: &mut self.txb_skip_luma_4, | 1355 | txb_skip: &mut self.txb_skip_luma_4, |
crates/ec-av1/src/decode.rsmodified+494 -41
| @@ -394,6 +394,38 @@ pub(crate) fn tx_depth_hits() -> usize { | |||
| 394 | TX_DEPTH_HITS.with(|c| c.get()) | 394 | TX_DEPTH_HITS.with(|c| c.get()) |
| 395 | } | 395 | } |
| 396 | 396 | ||
| 397 | +// lane-txselect: how many `txfm_split` symbols an inter frame's var-tx tree | ||
| 398 | +// read, and how many of those actually took the split, on the current thread | ||
| 399 | +// -- the same before/after counter pattern as [`TX_DEPTH_HITS`], proving a | ||
| 400 | +// stream exercised spec 5.11.17's `read_var_tx_size` rather than every block | ||
| 401 | +// coincidentally coding one whole-block transform. | ||
| 402 | +thread_local! { | ||
| 403 | + static TXFM_SPLIT_READS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 404 | + static TXFM_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 405 | + // This frame's own `tx_mode == TxMode::Select` and `reduced_tx_set` bits, | ||
| 406 | + // set once per inter tile by [`decode_inter_frame_tile_with_cdfs`] -- | ||
| 407 | + // `decode_inter_block` already carries forty parameters and both are | ||
| 408 | + // frame-constant. | ||
| 409 | + static TX_SELECT_INTER: std::cell::Cell<bool> = const { std::cell::Cell::new(false) }; | ||
| 410 | + static REDUCED_TX_SET_INTER: std::cell::Cell<bool> = const { std::cell::Cell::new(true) }; | ||
| 411 | +} | ||
| 412 | + | ||
| 413 | +/// Current value of [`TXFM_SPLIT_READS`]. | ||
| 414 | +pub(crate) fn txfm_split_reads() -> usize { | ||
| 415 | + TXFM_SPLIT_READS.with(|c| c.get()) | ||
| 416 | +} | ||
| 417 | + | ||
| 418 | +/// Current value of [`TXFM_SPLIT_HITS`]. | ||
| 419 | +pub(crate) fn txfm_split_hits() -> usize { | ||
| 420 | + TXFM_SPLIT_HITS.with(|c| c.get()) | ||
| 421 | +} | ||
| 422 | + | ||
| 423 | +/// Sets the current thread's [`TX_SELECT_INTER`]/[`REDUCED_TX_SET_INTER`]. | ||
| 424 | +pub(crate) fn set_inter_tx_mode(tx_select: bool, reduced_tx_set: bool) { | ||
| 425 | + TX_SELECT_INTER.with(|c| c.set(tx_select)); | ||
| 426 | + REDUCED_TX_SET_INTER.with(|c| c.set(reduced_tx_set)); | ||
| 427 | +} | ||
| 428 | + | ||
| 397 | // How many `partition_w16` reads (a 16x16 block's own partition symbol, key | 429 | // How many `partition_w16` reads (a 16x16 block's own partition symbol, key |
| 398 | // intra-frame path) resolved to `PARTITION_VERT_B` -- lane-rect16 r1: a | 430 | // intra-frame path) resolved to `PARTITION_VERT_B` -- lane-rect16 r1: a |
| 399 | // plain default-settings aomenc run over lavfi mandelbrot hits this arm on | 431 | // plain default-settings aomenc run over lavfi mandelbrot hits this arm on |
| @@ -1760,6 +1792,16 @@ struct Neighbours { | |||
| 1760 | /// `left_skip`. | 1792 | /// `left_skip`. |
| 1761 | above_skip: Vec<bool>, | 1793 | above_skip: Vec<bool>, |
| 1762 | left_skip: Vec<bool>, | 1794 | left_skip: Vec<bool>, |
| 1795 | + /// libaom's `above_txfm_context`/`left_txfm_context` (`TXFM_CONTEXT`), at | ||
| 1796 | + /// 4x4 mi granularity: the transform *width* (above) / *height* (left) in | ||
| 1797 | + /// pixels last written over each unit by `set_txfm_ctxs`/ | ||
| 1798 | + /// `txfm_partition_update`, which is what an inter block's `txfm_split` | ||
| 1799 | + /// symbol reads its context from (lane-txselect, spec 5.11.17). Zero | ||
| 1800 | + /// (libaom's own tile-start value) until a block writes one; a fresh | ||
| 1801 | + /// full-height `left` array is exactly libaom's per-superblock-row reset, | ||
| 1802 | + /// since each mi row is only ever visited inside one superblock row. | ||
| 1803 | + above_txfm: Vec<u8>, | ||
| 1804 | + left_txfm: Vec<u8>, | ||
| 1763 | /// Whether the block above/left of this column/row coded `skip_mode` | 1805 | /// Whether the block above/left of this column/row coded `skip_mode` |
| 1764 | /// (spec 5.11.23) -- `av1_get_skip_mode_context`'s own neighbour lookup, | 1806 | /// (spec 5.11.23) -- `av1_get_skip_mode_context`'s own neighbour lookup, |
| 1765 | /// lane-av1comp round 14. | 1807 | /// lane-av1comp round 14. |
| @@ -1882,6 +1924,8 @@ impl Neighbours { | |||
| 1882 | left_side_mi: vec![SB; rows * (SUB / MI)], | 1924 | left_side_mi: vec![SB; rows * (SUB / MI)], |
| 1883 | above_skip: vec![false; cols], | 1925 | above_skip: vec![false; cols], |
| 1884 | left_skip: vec![false; rows], | 1926 | left_skip: vec![false; rows], |
| 1927 | + above_txfm: vec![0u8; cols * (SUB / MI)], | ||
| 1928 | + left_txfm: vec![0u8; rows * (SUB / MI)], | ||
| 1885 | above_skip_mode: vec![false; cols], | 1929 | above_skip_mode: vec![false; cols], |
| 1886 | left_skip_mode: vec![false; rows], | 1930 | left_skip_mode: vec![false; rows], |
| 1887 | above_inter: vec![false; cols], | 1931 | above_inter: vec![false; cols], |
| @@ -5747,6 +5791,238 @@ fn read_tx_size( | |||
| 5747 | side >> depth | 5791 | side >> depth |
| 5748 | } | 5792 | } |
| 5749 | 5793 | ||
| 5794 | +/// `txfm_partition_context` (libaom `av1_common_int.h`): an inter block's | ||
| 5795 | +/// `txfm_split` context -- a category from the block's own largest square | ||
| 5796 | +/// transform and whether this unit already sits below it, times three, plus | ||
| 5797 | +/// the two neighbour terms (whether the transform last written above/left of | ||
| 5798 | +/// this unit is narrower/shorter than the unit itself). | ||
| 5799 | +fn txfm_partition_ctx(above_px: u8, left_px: u8, blk_max_px: usize, tx_px: usize) -> usize { | ||
| 5800 | + let above = usize::from(usize::from(above_px) < tx_px); | ||
| 5801 | + let left = usize::from(usize::from(left_px) < tx_px); | ||
| 5802 | + // `get_sqr_tx_size(max(block_size_wide, block_size_high))`, capped at the | ||
| 5803 | + // largest transform (`TX_64X64`); `TX_4X4`..`TX_64X64` index as | ||
| 5804 | + // `log2(px) - 2`. | ||
| 5805 | + let max_tx = blk_max_px.min(64); | ||
| 5806 | + let max_idx = max_tx.trailing_zeros() as usize - 2; | ||
| 5807 | + let category = usize::from(tx_px != max_tx && max_tx > 8) + (4 - max_idx) * 2; | ||
| 5808 | + category * 3 + above + left | ||
| 5809 | +} | ||
| 5810 | + | ||
| 5811 | +/// `txfm_partition_update` (libaom `av1_common_int.h`): once a var-tx unit | ||
| 5812 | +/// resolves, every mi cell its *parent* unit (`txb_px`) spans records the | ||
| 5813 | +/// resolved transform's own size. | ||
| 5814 | +fn txfm_partition_update( | ||
| 5815 | + n: &mut Neighbours, | ||
| 5816 | + (mi_r, mi_c): (usize, usize), | ||
| 5817 | + tx_px: usize, | ||
| 5818 | + txb_px: usize, | ||
| 5819 | +) { | ||
| 5820 | + for i in 0..txb_px / MI { | ||
| 5821 | + if let Some(cell) = n.left_txfm.get_mut(mi_r + i) { | ||
| 5822 | + *cell = tx_px as u8; | ||
| 5823 | + } | ||
| 5824 | + if let Some(cell) = n.above_txfm.get_mut(mi_c + i) { | ||
| 5825 | + *cell = tx_px as u8; | ||
| 5826 | + } | ||
| 5827 | + } | ||
| 5828 | +} | ||
| 5829 | + | ||
| 5830 | +/// `set_txfm_ctxs` (libaom `av1_common_int.h`): the non-var-tx write of the | ||
| 5831 | +/// same contexts -- a skipped *inter* block records its own block size rather | ||
| 5832 | +/// than its transform size. | ||
| 5833 | +fn set_txfm_ctxs( | ||
| 5834 | + n: &mut Neighbours, | ||
| 5835 | + (mi_r, mi_c): (usize, usize), | ||
| 5836 | + tx_px: usize, | ||
| 5837 | + w_mi: usize, | ||
| 5838 | + h_mi: usize, | ||
| 5839 | + skip_inter: bool, | ||
| 5840 | +) { | ||
| 5841 | + let bw = if skip_inter { w_mi * MI } else { tx_px }; | ||
| 5842 | + let bh = if skip_inter { h_mi * MI } else { tx_px }; | ||
| 5843 | + for i in 0..w_mi { | ||
| 5844 | + if let Some(cell) = n.above_txfm.get_mut(mi_c + i) { | ||
| 5845 | + *cell = bw as u8; | ||
| 5846 | + } | ||
| 5847 | + } | ||
| 5848 | + for i in 0..h_mi { | ||
| 5849 | + if let Some(cell) = n.left_txfm.get_mut(mi_r + i) { | ||
| 5850 | + *cell = bh as u8; | ||
| 5851 | + } | ||
| 5852 | + } | ||
| 5853 | +} | ||
| 5854 | + | ||
| 5855 | +/// libaom's `MAX_VARTX_DEPTH`: an inter block's transform tree halves at most | ||
| 5856 | +/// twice below its own largest transform. | ||
| 5857 | +const MAX_VARTX_DEPTH: usize = 2; | ||
| 5858 | + | ||
| 5859 | +/// `read_var_tx_size` (spec 5.11.17, libaom `decodeframe.c` | ||
| 5860 | +/// `read_tx_size_vartx`): the recursive `txfm_split` tree of one | ||
| 5861 | +/// max-transform-sized unit of an inter block, collecting the resolved leaf | ||
| 5862 | +/// transform units into `out` as `(row offset, col offset, side)` in mi units | ||
| 5863 | +/// -- exactly the order `decode_reconstruct_tx` later reads their | ||
| 5864 | +/// coefficients in. `blk_row`/`blk_col` are mi offsets inside the block; | ||
| 5865 | +/// `max_w_mi`/`max_h_mi` clip it to the true frame edge (`max_block_wide`/ | ||
| 5866 | +/// `max_block_high`). | ||
| 5867 | +#[allow(clippy::too_many_arguments)] | ||
| 5868 | +fn read_var_tx_size( | ||
| 5869 | + dec: &mut SymbolDecoder, | ||
| 5870 | + cdfs: &mut Cdfs, | ||
| 5871 | + n: &mut Neighbours, | ||
| 5872 | + at_mi: (usize, usize), | ||
| 5873 | + blk_max_px: usize, | ||
| 5874 | + (max_w_mi, max_h_mi): (usize, usize), | ||
| 5875 | + tx_px: usize, | ||
| 5876 | + depth: usize, | ||
| 5877 | + blk_row: usize, | ||
| 5878 | + blk_col: usize, | ||
| 5879 | + out: &mut Vec<(usize, usize, usize)>, | ||
| 5880 | +) { | ||
| 5881 | + if blk_row >= max_h_mi || blk_col >= max_w_mi { | ||
| 5882 | + return; | ||
| 5883 | + } | ||
| 5884 | + let unit = (at_mi.0 + blk_row, at_mi.1 + blk_col); | ||
| 5885 | + if depth == MAX_VARTX_DEPTH { | ||
| 5886 | + out.push((blk_row, blk_col, tx_px)); | ||
| 5887 | + txfm_partition_update(n, unit, tx_px, tx_px); | ||
| 5888 | + return; | ||
| 5889 | + } | ||
| 5890 | + let ctx = txfm_partition_ctx(n.above_txfm[unit.1], n.left_txfm[unit.0], blk_max_px, tx_px); | ||
| 5891 | + let split = dec.symbol(&mut cdfs.txfm_partition[ctx]) == 1; | ||
| 5892 | + TXFM_SPLIT_READS.with(|c| c.set(c.get() + 1)); | ||
| 5893 | + if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { | ||
| 5894 | + let (rng, _) = dec.debug_state(); | ||
| 5895 | + eprintln!( | ||
| 5896 | + "EC_ISTEP mi_row={} mi_col={} name=txfm_split val={} ctx={ctx} rng={rng}", | ||
| 5897 | + unit.0, | ||
| 5898 | + unit.1, | ||
| 5899 | + u8::from(split) | ||
| 5900 | + ); | ||
| 5901 | + } | ||
| 5902 | + if !split { | ||
| 5903 | + out.push((blk_row, blk_col, tx_px)); | ||
| 5904 | + txfm_partition_update(n, unit, tx_px, tx_px); | ||
| 5905 | + return; | ||
| 5906 | + } | ||
| 5907 | + TXFM_SPLIT_HITS.with(|c| c.set(c.get() + 1)); | ||
| 5908 | + let sub = tx_px / 2; | ||
| 5909 | + if sub == 4 { | ||
| 5910 | + // libaom's `sub_txs == TX_4X4` early return: the whole 8x8 unit is | ||
| 5911 | + // marked 4x4 (four transform units, raster order) without recursing. | ||
| 5912 | + for row in 0..2 { | ||
| 5913 | + for col in 0..2 { | ||
| 5914 | + if blk_row + row < max_h_mi && blk_col + col < max_w_mi { | ||
| 5915 | + out.push((blk_row + row, blk_col + col, 4)); | ||
| 5916 | + } | ||
| 5917 | + } | ||
| 5918 | + } | ||
| 5919 | + txfm_partition_update(n, unit, 4, tx_px); | ||
| 5920 | + return; | ||
| 5921 | + } | ||
| 5922 | + for row in (0..tx_px / MI).step_by(sub / MI) { | ||
| 5923 | + for col in (0..tx_px / MI).step_by(sub / MI) { | ||
| 5924 | + read_var_tx_size( | ||
| 5925 | + dec, | ||
| 5926 | + cdfs, | ||
| 5927 | + n, | ||
| 5928 | + at_mi, | ||
| 5929 | + blk_max_px, | ||
| 5930 | + (max_w_mi, max_h_mi), | ||
| 5931 | + sub, | ||
| 5932 | + depth + 1, | ||
| 5933 | + blk_row + row, | ||
| 5934 | + blk_col + col, | ||
| 5935 | + out, | ||
| 5936 | + ); | ||
| 5937 | + } | ||
| 5938 | + } | ||
| 5939 | +} | ||
| 5940 | + | ||
| 5941 | +/// `read_block_tx_size` (libaom `decodeframe.c` `parse_decode_block`'s tx | ||
| 5942 | +/// branch): every block of a `TxMode::Select` inter frame codes its transform | ||
| 5943 | +/// size right after its own mode info -- an inter non-skip block through the | ||
| 5944 | +/// recursive var-tx tree ([`read_var_tx_size`], whose leaf list this returns), | ||
| 5945 | +/// every other block through the intra `tx_depth` symbol (a skipped inter | ||
| 5946 | +/// block codes no symbol at all) plus a `set_txfm_ctxs` write. Returns the | ||
| 5947 | +/// block's own resolved transform side and the leaf list, the latter only | ||
| 5948 | +/// when the tree resolved to more than one transform unit. | ||
| 5949 | +#[allow(clippy::too_many_arguments)] | ||
| 5950 | +fn read_block_tx_size( | ||
| 5951 | + dec: &mut SymbolDecoder, | ||
| 5952 | + cdfs: &mut Cdfs, | ||
| 5953 | + n: &mut Neighbours, | ||
| 5954 | + at_mi: (usize, usize), | ||
| 5955 | + side: usize, | ||
| 5956 | + (mi_cols, mi_rows): (usize, usize), | ||
| 5957 | + is_inter: bool, | ||
| 5958 | + skip: bool, | ||
| 5959 | +) -> Result<(usize, Option<Vec<(usize, usize, usize)>>)> { | ||
| 5960 | + if !TX_SELECT_INTER.with(std::cell::Cell::get) { | ||
| 5961 | + return Ok((side, None)); | ||
| 5962 | + } | ||
| 5963 | + let side_mi = side / MI; | ||
| 5964 | + if is_inter && !skip { | ||
| 5965 | + let max_tx = side.min(64); | ||
| 5966 | + let max_w_mi = side_mi.min(mi_cols.saturating_sub(at_mi.1)); | ||
| 5967 | + let max_h_mi = side_mi.min(mi_rows.saturating_sub(at_mi.0)); | ||
| 5968 | + let mut leaves = Vec::new(); | ||
| 5969 | + let step = max_tx / MI; | ||
| 5970 | + for row in (0..side_mi).step_by(step) { | ||
| 5971 | + for col in (0..side_mi).step_by(step) { | ||
| 5972 | + read_var_tx_size( | ||
| 5973 | + dec, | ||
| 5974 | + cdfs, | ||
| 5975 | + n, | ||
| 5976 | + at_mi, | ||
| 5977 | + side, | ||
| 5978 | + (max_w_mi, max_h_mi), | ||
| 5979 | + max_tx, | ||
| 5980 | + 0, | ||
| 5981 | + row, | ||
| 5982 | + col, | ||
| 5983 | + &mut leaves, | ||
| 5984 | + ); | ||
| 5985 | + } | ||
| 5986 | + } | ||
| 5987 | + let single = leaves.len() == 1 && leaves[0].2 == side; | ||
| 5988 | + let resolved = leaves.last().map_or(side, |l| l.2); | ||
| 5989 | + return Ok((resolved, (!single).then_some(leaves))); | ||
| 5990 | + } | ||
| 5991 | + let tx = if is_inter { | ||
| 5992 | + side.min(64) | ||
| 5993 | + } else { | ||
| 5994 | + let resolved = read_tx_size(dec, cdfs, n, at_mi, side); | ||
| 5995 | + if resolved != side { | ||
| 5996 | + // An intra block inside an inter frame whose `tx_depth` splits its | ||
| 5997 | + // luma transform needs the per-transform-unit intra prediction | ||
| 5998 | + // loop `decode_block` runs for a key frame; this path predicts the | ||
| 5999 | + // whole block at once, so refuse rather than mis-reconstruct. | ||
| 6000 | + return Err(unsupported( | ||
| 6001 | + "an intra block in an inter frame whose tx_depth splits its luma transform \ | ||
| 6002 | + (round 1)", | ||
| 6003 | + )); | ||
| 6004 | + } | ||
| 6005 | + resolved | ||
| 6006 | + }; | ||
| 6007 | + set_txfm_ctxs(n, at_mi, tx, side_mi, side_mi, skip && is_inter); | ||
| 6008 | + Ok((tx, None)) | ||
| 6009 | +} | ||
| 6010 | + | ||
| 6011 | +/// The [`TxbSet`] one leaf of an inter block's var-tx tree reads its | ||
| 6012 | +/// coefficient tables from -- the inter counterpart of [`txbset_for`]. | ||
| 6013 | +fn inter_txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet { | ||
| 6014 | + match tx_px { | ||
| 6015 | + 32 => TxbSet::Luma32Inter, | ||
| 6016 | + 16 if reduced_tx_set => TxbSet::Luma16Inter, | ||
| 6017 | + 16 => TxbSet::Luma16InterSet1, | ||
| 6018 | + 8 if reduced_tx_set => TxbSet::Luma8Inter, | ||
| 6019 | + 8 => TxbSet::Luma8InterSet1, | ||
| 6020 | + 4 if reduced_tx_set => TxbSet::Luma4Inter, | ||
| 6021 | + 4 => TxbSet::Luma4InterSet1, | ||
| 6022 | + _ => unreachable!("a var-tx leaf is never wider than a 64x64 block's 32x32 sub-transform"), | ||
| 6023 | + } | ||
| 6024 | +} | ||
| 6025 | + | ||
| 5750 | /// The luma coefficient scan table for a resolved transform side -- 32/16/8/4, | 6026 | /// The luma coefficient scan table for a resolved transform side -- 32/16/8/4, |
| 5751 | /// the only four sizes a `TxMode::Select` block's coded coefficient grid | 6027 | /// the only four sizes a `TxMode::Select` block's coded coefficient grid |
| 5752 | /// ([`read_tx_size`]'s resolved side, or 32 at the 64x64 corner case) can be. | 6028 | /// ([`read_tx_size`]'s resolved side, or 32 at the 64x64 corner case) can be. |
| @@ -7759,9 +8035,15 @@ fn read_inter_plane( | |||
| 7759 | // (`plane_idx == 0`), where the `TxbSet`'s own symbol (or the true | 8035 | // (`plane_idx == 0`), where the `TxbSet`'s own symbol (or the true |
| 7760 | // `DCT_DCT` default at 32-point+) already resolves it without help. | 8036 | // `DCT_DCT` default at 32-point+) already resolves it without help. |
| 7761 | inherited_luma_tx_type: Option<TxType>, | 8037 | inherited_luma_tx_type: Option<TxType>, |
| 8038 | + // lane-txselect: the luma `txb_skip_ctx` of a transform unit smaller than | ||
| 8039 | + // its own block (spec `get_txb_ctx_general`'s `plane_bsize != tx_size` | ||
| 8040 | + // branch, [`Neighbours::luma_skip_ctx`]) -- `None` for the whole-block | ||
| 8041 | + // transform every non-var-tx caller reads, whose plane-0 context is the | ||
| 8042 | + // lone-transform-unit 0. | ||
| 8043 | + luma_skip_ctx: Option<usize>, | ||
| 7762 | ) -> Result<(Vec<i32>, TxType)> { | 8044 | ) -> Result<(Vec<i32>, TxType)> { |
| 7763 | let skip_ctx = if plane_idx == 0 { | 8045 | let skip_ctx = if plane_idx == 0 { |
| 7764 | - 0 | 8046 | + luma_skip_ctx.unwrap_or(0) |
| 7765 | } else { | 8047 | } else { |
| 7766 | usize::from(around.0) + usize::from(around.1) | 8048 | usize::from(around.0) + usize::from(around.1) |
| 7767 | }; | 8049 | }; |
| @@ -8914,6 +9196,12 @@ fn decode_inter_block( | |||
| 8914 | // common `record_inter` call below (which would otherwise stamp the | 9196 | // common `record_inter` call below (which would otherwise stamp the |
| 8915 | // single-ref ALTREF-special-case default over it). | 9197 | // single-ref ALTREF-special-case default over it). |
| 8916 | let mut compound_ctx: Option<(i8, u8, u8)> = None; | 9198 | let mut compound_ctx: Option<(i8, u8, u8)> = None; |
| 9199 | + // lane-txselect: `read_block_tx_size`'s leaf transform units (spec | ||
| 9200 | + // 5.11.17), `Some` only when this block's var-tx tree resolved to more | ||
| 9201 | + // than one luma transform -- read back by the residual loop, the | ||
| 9202 | + // coefficient-context write-back and the loop-filter grid fill below. | ||
| 9203 | + let mut vartx_leaves: Option<Vec<(usize, usize, usize)>> = None; | ||
| 9204 | + let at_mi = (r * (SUB / MI), c * (SUB / MI)); | ||
| 8917 | if is_inter { | 9205 | if is_inter { |
| 8918 | let above_nbr = has_above.then(|| NeighbourRef { | 9206 | let above_nbr = has_above.then(|| NeighbourRef { |
| 8919 | is_inter: above_inter, | 9207 | is_inter: above_inter, |
| @@ -9545,6 +9833,17 @@ fn decode_inter_block( | |||
| 9545 | mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); | 9833 | mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); |
| 9546 | } | 9834 | } |
| 9547 | 9835 | ||
| 9836 | + vartx_leaves = read_block_tx_size( | ||
| 9837 | + dec, | ||
| 9838 | + cdfs, | ||
| 9839 | + neighbours, | ||
| 9840 | + at_mi, | ||
| 9841 | + side, | ||
| 9842 | + (mi_cols as usize, mi_rows as usize), | ||
| 9843 | + true, | ||
| 9844 | + skip, | ||
| 9845 | + )? | ||
| 9846 | + .1; | ||
| 9548 | if skip { | 9847 | if skip { |
| 9549 | y.reconstruct_mc_rect( | 9848 | y.reconstruct_mc_rect( |
| 9550 | px, | 9849 | px, |
| @@ -9579,22 +9878,70 @@ fn decode_inter_block( | |||
| 9579 | } else { | 9878 | } else { |
| 9580 | let around = neighbours.around(at, side); | 9879 | let around = neighbours.around(at, side); |
| 9581 | let luma_tx_type; | 9880 | let luma_tx_type; |
| 9582 | - (luma_grid, luma_tx_type) = read_inter_plane( | 9881 | + if let Some(leaves) = vartx_leaves.clone() { |
| 9583 | - dec, | 9882 | + // spec 5.11.17's transform tree, leaf by leaf in the order |
| 9584 | - cdfs, | 9883 | + // `read_var_tx_size` coded it: each unit reads its own |
| 9585 | - luma_set_inter, | 9884 | + // coefficients against the neighbour magnitudes the |
| 9586 | - scan_luma, | 9885 | + // earlier units already wrote, and reconstructs over its |
| 9587 | - 0, | 9886 | + // own slice of the block's motion-compensated predictor. |
| 9588 | - around[0], | 9887 | + let reduced = REDUCED_TX_SET_INTER.with(std::cell::Cell::get); |
| 9589 | - mode_for_tx, | 9888 | + let mut first_tx_type = TxType::DctDct; |
| 9590 | - y, | 9889 | + for (idx, &(row, col, tx_px)) in leaves.iter().enumerate() { |
| 9591 | - px, | 9890 | + let tu_mi = (at_mi.0 + row, at_mi.1 + col); |
| 9592 | - py, | 9891 | + let (tu_px, tu_py) = (px + col * MI, py + row * MI); |
| 9593 | - side, | 9892 | + let mut tu_pred = Vec::with_capacity(tx_px * tx_px); |
| 9594 | - base_q_idx, | 9893 | + for rr in 0..tx_px { |
| 9595 | - &pred_y, | 9894 | + let start = (row * MI + rr) * side + col * MI; |
| 9596 | - None, | 9895 | + tu_pred.extend_from_slice(&pred_y[start..start + tx_px]); |
| 9597 | - )?; | 9896 | + } |
| 9897 | + let scan = default_scan(tx_px); | ||
| 9898 | + let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI); | ||
| 9899 | + let (tu_grid, tu_tx_type) = read_inter_plane( | ||
| 9900 | + dec, | ||
| 9901 | + cdfs, | ||
| 9902 | + inter_txbset_for(tx_px, reduced), | ||
| 9903 | + &scan, | ||
| 9904 | + 0, | ||
| 9905 | + neighbours.around_mi(tu_mi, tx_px)[0], | ||
| 9906 | + mode_for_tx, | ||
| 9907 | + y, | ||
| 9908 | + tu_px, | ||
| 9909 | + tu_py, | ||
| 9910 | + tx_px, | ||
| 9911 | + base_q_idx, | ||
| 9912 | + &tu_pred, | ||
| 9913 | + None, | ||
| 9914 | + Some(tu_skip_ctx), | ||
| 9915 | + )?; | ||
| 9916 | + if idx == 0 { | ||
| 9917 | + first_tx_type = tu_tx_type; | ||
| 9918 | + } | ||
| 9919 | + neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid); | ||
| 9920 | + } | ||
| 9921 | + // `av1_get_tx_type`'s chroma lookup scales the chroma | ||
| 9922 | + // position back to luma, so an inter block's chroma | ||
| 9923 | + // inherits the *first* (top-left) luma unit's coded type. | ||
| 9924 | + luma_tx_type = first_tx_type; | ||
| 9925 | + luma_grid = vec![0i32; side * side]; | ||
| 9926 | + } else { | ||
| 9927 | + (luma_grid, luma_tx_type) = read_inter_plane( | ||
| 9928 | + dec, | ||
| 9929 | + cdfs, | ||
| 9930 | + luma_set_inter, | ||
| 9931 | + scan_luma, | ||
| 9932 | + 0, | ||
| 9933 | + around[0], | ||
| 9934 | + mode_for_tx, | ||
| 9935 | + y, | ||
| 9936 | + px, | ||
| 9937 | + py, | ||
| 9938 | + side, | ||
| 9939 | + base_q_idx, | ||
| 9940 | + &pred_y, | ||
| 9941 | + None, | ||
| 9942 | + None, | ||
| 9943 | + )?; | ||
| 9944 | + } | ||
| 9598 | u_grid = read_inter_plane( | 9945 | u_grid = read_inter_plane( |
| 9599 | dec, | 9946 | dec, |
| 9600 | cdfs, | 9947 | cdfs, |
| @@ -9610,6 +9957,7 @@ fn decode_inter_block( | |||
| 9610 | base_q_idx, | 9957 | base_q_idx, |
| 9611 | &pred_u, | 9958 | &pred_u, |
| 9612 | Some(luma_tx_type), | 9959 | Some(luma_tx_type), |
| 9960 | + None, | ||
| 9613 | )? | 9961 | )? |
| 9614 | .0; | 9962 | .0; |
| 9615 | v_grid = read_inter_plane( | 9963 | v_grid = read_inter_plane( |
| @@ -9627,6 +9975,7 @@ fn decode_inter_block( | |||
| 9627 | base_q_idx, | 9975 | base_q_idx, |
| 9628 | &pred_v, | 9976 | &pred_v, |
| 9629 | Some(luma_tx_type), | 9977 | Some(luma_tx_type), |
| 9978 | + None, | ||
| 9630 | )? | 9979 | )? |
| 9631 | .0; | 9980 | .0; |
| 9632 | } | 9981 | } |
| @@ -10244,6 +10593,17 @@ fn decode_inter_block( | |||
| 10244 | interintra_blend(v, cpx, cpy, chroma_side, ii, wedge_mask, &mut pred_v); | 10593 | interintra_blend(v, cpx, cpy, chroma_side, ii, wedge_mask, &mut pred_v); |
| 10245 | } | 10594 | } |
| 10246 | 10595 | ||
| 10596 | + vartx_leaves = read_block_tx_size( | ||
| 10597 | + dec, | ||
| 10598 | + cdfs, | ||
| 10599 | + neighbours, | ||
| 10600 | + at_mi, | ||
| 10601 | + side, | ||
| 10602 | + (mi_cols as usize, mi_rows as usize), | ||
| 10603 | + true, | ||
| 10604 | + skip, | ||
| 10605 | + )? | ||
| 10606 | + .1; | ||
| 10247 | if skip { | 10607 | if skip { |
| 10248 | y.reconstruct_mc_rect( | 10608 | y.reconstruct_mc_rect( |
| 10249 | px, | 10609 | px, |
| @@ -10278,22 +10638,70 @@ fn decode_inter_block( | |||
| 10278 | } else { | 10638 | } else { |
| 10279 | let around = neighbours.around(at, side); | 10639 | let around = neighbours.around(at, side); |
| 10280 | let luma_tx_type; | 10640 | let luma_tx_type; |
| 10281 | - (luma_grid, luma_tx_type) = read_inter_plane( | 10641 | + if let Some(leaves) = vartx_leaves.clone() { |
| 10282 | - dec, | 10642 | + // spec 5.11.17's transform tree, leaf by leaf in the order |
| 10283 | - cdfs, | 10643 | + // `read_var_tx_size` coded it: each unit reads its own |
| 10284 | - luma_set_inter, | 10644 | + // coefficients against the neighbour magnitudes the |
| 10285 | - scan_luma, | 10645 | + // earlier units already wrote, and reconstructs over its |
| 10286 | - 0, | 10646 | + // own slice of the block's motion-compensated predictor. |
| 10287 | - around[0], | 10647 | + let reduced = REDUCED_TX_SET_INTER.with(std::cell::Cell::get); |
| 10288 | - mode_for_tx, | 10648 | + let mut first_tx_type = TxType::DctDct; |
| 10289 | - y, | 10649 | + for (idx, &(row, col, tx_px)) in leaves.iter().enumerate() { |
| 10290 | - px, | 10650 | + let tu_mi = (at_mi.0 + row, at_mi.1 + col); |
| 10291 | - py, | 10651 | + let (tu_px, tu_py) = (px + col * MI, py + row * MI); |
| 10292 | - side, | 10652 | + let mut tu_pred = Vec::with_capacity(tx_px * tx_px); |
| 10293 | - base_q_idx, | 10653 | + for rr in 0..tx_px { |
| 10294 | - &pred_y, | 10654 | + let start = (row * MI + rr) * side + col * MI; |
| 10295 | - None, | 10655 | + tu_pred.extend_from_slice(&pred_y[start..start + tx_px]); |
| 10296 | - )?; | 10656 | + } |
| 10657 | + let scan = default_scan(tx_px); | ||
| 10658 | + let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI); | ||
| 10659 | + let (tu_grid, tu_tx_type) = read_inter_plane( | ||
| 10660 | + dec, | ||
| 10661 | + cdfs, | ||
| 10662 | + inter_txbset_for(tx_px, reduced), | ||
| 10663 | + &scan, | ||
| 10664 | + 0, | ||
| 10665 | + neighbours.around_mi(tu_mi, tx_px)[0], | ||
| 10666 | + mode_for_tx, | ||
| 10667 | + y, | ||
| 10668 | + tu_px, | ||
| 10669 | + tu_py, | ||
| 10670 | + tx_px, | ||
| 10671 | + base_q_idx, | ||
| 10672 | + &tu_pred, | ||
| 10673 | + None, | ||
| 10674 | + Some(tu_skip_ctx), | ||
| 10675 | + )?; | ||
| 10676 | + if idx == 0 { | ||
| 10677 | + first_tx_type = tu_tx_type; | ||
| 10678 | + } | ||
| 10679 | + neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid); | ||
| 10680 | + } | ||
| 10681 | + // `av1_get_tx_type`'s chroma lookup scales the chroma | ||
| 10682 | + // position back to luma, so an inter block's chroma | ||
| 10683 | + // inherits the *first* (top-left) luma unit's coded type. | ||
| 10684 | + luma_tx_type = first_tx_type; | ||
| 10685 | + luma_grid = vec![0i32; side * side]; | ||
| 10686 | + } else { | ||
| 10687 | + (luma_grid, luma_tx_type) = read_inter_plane( | ||
| 10688 | + dec, | ||
| 10689 | + cdfs, | ||
| 10690 | + luma_set_inter, | ||
| 10691 | + scan_luma, | ||
| 10692 | + 0, | ||
| 10693 | + around[0], | ||
| 10694 | + mode_for_tx, | ||
| 10695 | + y, | ||
| 10696 | + px, | ||
| 10697 | + py, | ||
| 10698 | + side, | ||
| 10699 | + base_q_idx, | ||
| 10700 | + &pred_y, | ||
| 10701 | + None, | ||
| 10702 | + None, | ||
| 10703 | + )?; | ||
| 10704 | + } | ||
| 10297 | u_grid = read_inter_plane( | 10705 | u_grid = read_inter_plane( |
| 10298 | dec, | 10706 | dec, |
| 10299 | cdfs, | 10707 | cdfs, |
| @@ -10309,6 +10717,7 @@ fn decode_inter_block( | |||
| 10309 | base_q_idx, | 10717 | base_q_idx, |
| 10310 | &pred_u, | 10718 | &pred_u, |
| 10311 | Some(luma_tx_type), | 10719 | Some(luma_tx_type), |
| 10720 | + None, | ||
| 10312 | )? | 10721 | )? |
| 10313 | .0; | 10722 | .0; |
| 10314 | v_grid = read_inter_plane( | 10723 | v_grid = read_inter_plane( |
| @@ -10326,6 +10735,7 @@ fn decode_inter_block( | |||
| 10326 | base_q_idx, | 10735 | base_q_idx, |
| 10327 | &pred_v, | 10736 | &pred_v, |
| 10328 | Some(luma_tx_type), | 10737 | Some(luma_tx_type), |
| 10738 | + None, | ||
| 10329 | )? | 10739 | )? |
| 10330 | .0; | 10740 | .0; |
| 10331 | } | 10741 | } |
| @@ -10434,6 +10844,16 @@ fn decode_inter_block( | |||
| 10434 | } | 10844 | } |
| 10435 | } | 10845 | } |
| 10436 | 10846 | ||
| 10847 | + read_block_tx_size( | ||
| 10848 | + dec, | ||
| 10849 | + cdfs, | ||
| 10850 | + neighbours, | ||
| 10851 | + at_mi, | ||
| 10852 | + side, | ||
| 10853 | + (mi_cols as usize, mi_rows as usize), | ||
| 10854 | + false, | ||
| 10855 | + skip, | ||
| 10856 | + )?; | ||
| 10437 | let reach = Reach::of(side, px, py, y.width, y.height); | 10857 | let reach = Reach::of(side, px, py, y.width, y.height); |
| 10438 | if skip { | 10858 | if skip { |
| 10439 | y.reconstruct( | 10859 | y.reconstruct( |
| @@ -10559,14 +10979,22 @@ fn decode_inter_block( | |||
| 10559 | r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0 | 10979 | r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0 |
| 10560 | ); | 10980 | ); |
| 10561 | } | 10981 | } |
| 10562 | - neighbours.record_rect( | 10982 | + if vartx_leaves.is_some() { |
| 10563 | - at, | 10983 | + // Plane 0 is already correct per transform unit |
| 10564 | - write_w, | 10984 | + // ([`Neighbours::record_mi_luma`] above); this writes everything else |
| 10565 | - write_h, | 10985 | + // [`Neighbours::record_rect`] would (a var-tx block is always square, |
| 10566 | - mode_for_tx, | 10986 | + // so `write_w == write_h == side`). |
| 10567 | - uv_predict_mode, | 10987 | + neighbours.record_split_luma(at, side, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]); |
| 10568 | - &[luma_grid, u_grid, v_grid], | 10988 | + } else { |
| 10569 | - ); | 10989 | + neighbours.record_rect( |
| 10990 | + at, | ||
| 10991 | + write_w, | ||
| 10992 | + write_h, | ||
| 10993 | + mode_for_tx, | ||
| 10994 | + uv_predict_mode, | ||
| 10995 | + &[luma_grid, u_grid, v_grid], | ||
| 10996 | + ); | ||
| 10997 | + } | ||
| 10570 | neighbours.record_inter_rect( | 10998 | neighbours.record_inter_rect( |
| 10571 | at, | 10999 | at, |
| 10572 | write_w, | 11000 | write_w, |
| @@ -10603,6 +11031,25 @@ fn decode_inter_block( | |||
| 10603 | ref_frame_for_lf | 11031 | ref_frame_for_lf |
| 10604 | }, | 11032 | }, |
| 10605 | ); | 11033 | ); |
| 11034 | + // lane-txselect: a var-tx block's deblock edges follow its own transform | ||
| 11035 | + // units, not the block. Chroma still reads `tx_h_grid / 2` (the block's | ||
| 11036 | + // uv transform is not split) -- a known corner-cut of this round. | ||
| 11037 | + if let Some(leaves) = &vartx_leaves { | ||
| 11038 | + for &(row, col, tx_px) in leaves { | ||
| 11039 | + neighbours.fill_lf_grid_rect( | ||
| 11040 | + (at_mi.0 + row, at_mi.1 + col), | ||
| 11041 | + tx_px / MI, | ||
| 11042 | + tx_px / MI, | ||
| 11043 | + tx_px as u8, | ||
| 11044 | + tx_px as u8, | ||
| 11045 | + if globalmv_for_lf { | ||
| 11046 | + -ref_frame_for_lf | ||
| 11047 | + } else { | ||
| 11048 | + ref_frame_for_lf | ||
| 11049 | + }, | ||
| 11050 | + ); | ||
| 11051 | + } | ||
| 11052 | + } | ||
| 10606 | Ok(()) | 11053 | Ok(()) |
| 10607 | } | 11054 | } |
| 10608 | 11055 | ||
| @@ -11105,6 +11552,7 @@ fn decode_inter_block8( | |||
| 11105 | base_q_idx, | 11552 | base_q_idx, |
| 11106 | &pred_y, | 11553 | &pred_y, |
| 11107 | None, | 11554 | None, |
| 11555 | + None, | ||
| 11108 | )?; | 11556 | )?; |
| 11109 | u_grid = read_inter_plane( | 11557 | u_grid = read_inter_plane( |
| 11110 | dec, | 11558 | dec, |
| @@ -11121,6 +11569,7 @@ fn decode_inter_block8( | |||
| 11121 | base_q_idx, | 11569 | base_q_idx, |
| 11122 | &pred_u, | 11570 | &pred_u, |
| 11123 | Some(luma_tx_type), | 11571 | Some(luma_tx_type), |
| 11572 | + None, | ||
| 11124 | )? | 11573 | )? |
| 11125 | .0; | 11574 | .0; |
| 11126 | v_grid = read_inter_plane( | 11575 | v_grid = read_inter_plane( |
| @@ -11138,6 +11587,7 @@ fn decode_inter_block8( | |||
| 11138 | base_q_idx, | 11587 | base_q_idx, |
| 11139 | &pred_v, | 11588 | &pred_v, |
| 11140 | Some(luma_tx_type), | 11589 | Some(luma_tx_type), |
| 11590 | + None, | ||
| 11141 | )? | 11591 | )? |
| 11142 | .0; | 11592 | .0; |
| 11143 | } | 11593 | } |
| @@ -11430,6 +11880,7 @@ fn decode_inter_block8( | |||
| 11430 | base_q_idx, | 11880 | base_q_idx, |
| 11431 | &pred_y, | 11881 | &pred_y, |
| 11432 | None, | 11882 | None, |
| 11883 | + None, | ||
| 11433 | )?; | 11884 | )?; |
| 11434 | u_grid = read_inter_plane( | 11885 | u_grid = read_inter_plane( |
| 11435 | dec, | 11886 | dec, |
| @@ -11446,6 +11897,7 @@ fn decode_inter_block8( | |||
| 11446 | base_q_idx, | 11897 | base_q_idx, |
| 11447 | &pred_u, | 11898 | &pred_u, |
| 11448 | Some(luma_tx_type), | 11899 | Some(luma_tx_type), |
| 11900 | + None, | ||
| 11449 | )? | 11901 | )? |
| 11450 | .0; | 11902 | .0; |
| 11451 | v_grid = read_inter_plane( | 11903 | v_grid = read_inter_plane( |
| @@ -11463,6 +11915,7 @@ fn decode_inter_block8( | |||
| 11463 | base_q_idx, | 11915 | base_q_idx, |
| 11464 | &pred_v, | 11916 | &pred_v, |
| 11465 | Some(luma_tx_type), | 11917 | Some(luma_tx_type), |
| 11918 | + None, | ||
| 11466 | )? | 11919 | )? |
| 11467 | .0; | 11920 | .0; |
| 11468 | } | 11921 | } |