forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-cdffwd2': decode non-reduced inter tx sets (DTT9_IDTX_1DDCT, ALL16)

Browse files at this commit

3a8f2f26a59f0211ff86cca51637878ece035b1bAhmet Kaan GümüşParent: 9cd7fd08cc4428
Three rounds. reduced_tx_set=false inter streams now decode: 12- and
16-symbol ext-tx CDF tables, nine new TxTypes (FLIPADST combos via the
ADST kernel plus flip pass), forwarding/adaptation wiring, and the
reduced_tx_set gate threaded through the inter tile path. Pinned
forwarding stream's luma now bit-exact all frames; a small residual
chroma-U defect on that pin is separate and stays open.
crates/ec-av1/src/cdf.rsmodified+20 -0
@@ -1105,6 +1105,26 @@ pub const INTER_TX_TYPE_SET3_16: [u16; 3] = [1998, 32768, 0];
1105 /// `default_inter_ext_tx_cdf[EXT_TX_SET_DCT_IDTX][TX_8X8]`).1105 /// `default_inter_ext_tx_cdf[EXT_TX_SET_DCT_IDTX][TX_8X8]`).
1106 pub const INTER_TX_TYPE_SET3_8: [u16; 3] = [4167, 32768, 0];1106 pub const INTER_TX_TYPE_SET3_8: [u16; 3] = [4167, 32768, 0];
1107 1107
1108+/// `Default_Inter_Ext_Tx_Cdf`'s `TX_SET_INTER_2` (`EXT_TX_SET_DTT9_IDTX_1DDCT`)
1109+/// row for `TX_16X16` (lane-cdffwd2, spec 9.4/5.11.48): the twelve-symbol
1110+/// transform type of an `is_inter` 16x16 luma transform when `reduced_tx_set
1111+/// == 0` -- `av1_get_ext_tx_set_type`'s `av1_ext_tx_set_lookup[1][1]`, not
1112+/// [`INTER_TX_TYPE_SET3_16`]'s two-symbol reduced set (libaom
1113+/// `entropymode.c` `default_inter_ext_tx_cdf[2][TX_16X16]`).
1114+pub const INTER_TX_TYPE_SET2_16: [u16; 13] = [
1115+ 770, 2421, 5225, 12907, 15819, 18927, 21561, 24089, 26595, 28526, 30529, 32768, 0,
1116+];
1117+
1118+/// `Default_Inter_Ext_Tx_Cdf`'s `TX_SET_INTER_1` (`EXT_TX_SET_ALL16`) row for
1119+/// `TX_8X8` (lane-cdffwd2): the full sixteen-symbol transform type of an
1120+/// `is_inter` 8x8 luma transform when `reduced_tx_set == 0`
1121+/// (`av1_ext_tx_set_lookup[1][0]`, libaom `entropymode.c`
1122+/// `default_inter_ext_tx_cdf[1][TX_8X8]`).
1123+pub const INTER_TX_TYPE_SET1_8: [u16; 17] = [
1124+ 1645, 2573, 4778, 5711, 7807, 8622, 10522, 15357, 17674, 20408, 22517, 25010, 27116, 28856,
1125+ 30749, 32768, 0,
1126+];
1127+
1108 // The inter-frame tables below (spec 9.4) support the syntax an inter block1128 // The inter-frame tables below (spec 9.4) support the syntax an inter block
1109 // needs: whether it is coded as intra at all, which reference frame and1129 // needs: whether it is coded as intra at all, which reference frame and
1110 // motion vector it takes when it is not. The compound-reference tables1130 // motion vector it takes when it is not. The compound-reference tables
crates/ec-av1/src/cdf_state.rsmodified+47 -0
@@ -37,6 +37,13 @@ pub(crate) enum TxbSet {
37 /// reads, but its own two-symbol `tx_type` table rather than `Luma16`'s37 /// reads, but its own two-symbol `tx_type` table rather than `Luma16`'s
38 /// five-symbol, mode-indexed one.38 /// five-symbol, mode-indexed one.
39 Luma16Inter,39 Luma16Inter,
40+ /// [`Luma16Inter`](TxbSet::Luma16Inter)'s `reduced_tx_set: false`
41+ /// counterpart (lane-cdffwd2, root-caused off `cdfflake-stream-seed45`):
42+ /// the same coefficient tables, but the twelve-symbol
43+ /// `EXT_TX_SET_DTT9_IDTX_1DDCT` `tx_type` table
44+ /// ([`crate::cdf::INTER_TX_TYPE_SET2_16`]) rather than `Luma16Inter`'s
45+ /// two-symbol reduced one.
46+ Luma16InterSet1,
40 /// The 8x8 luma transform of an intra 8x8 leaf under a straddling 16x1647 /// The 8x8 luma transform of an intra 8x8 leaf under a straddling 16x16
41 /// block (lane-av1-rect). An `is_inter` leaf reads48 /// block (lane-av1-rect). An `is_inter` leaf reads
42 /// [`Luma8Inter`](TxbSet::Luma8Inter) instead.49 /// [`Luma8Inter`](TxbSet::Luma8Inter) instead.
@@ -55,6 +62,10 @@ pub(crate) enum TxbSet {
55 /// adapted table from the 16x16 and 32x32 sizes' own entries in the same62 /// adapted table from the 16x16 and 32x32 sizes' own entries in the same
56 /// set, per `entropymode.c`).63 /// set, per `entropymode.c`).
57 Luma8Inter,64 Luma8Inter,
65+ /// [`Luma8Inter`](TxbSet::Luma8Inter)'s `reduced_tx_set: false`
66+ /// counterpart (lane-cdffwd2): the sixteen-symbol `EXT_TX_SET_ALL16`
67+ /// `tx_type` table ([`crate::cdf::INTER_TX_TYPE_SET1_8`]).
68+ Luma8InterSet1,
58 /// The 4x4 luma transform of a `TxMode::Select` 8x8 leaf or 16x16 block69 /// The 4x4 luma transform of a `TxMode::Select` 8x8 leaf or 16x16 block
59 /// whose `tx_depth` resolves all the way down (lane-av1tx4). An70 /// whose `tx_depth` resolves all the way down (lane-av1tx4). An
60 /// `is_inter` block has no writer path yet, so this crate has no71 /// `is_inter` block has no writer path yet, so this crate has no
@@ -287,6 +298,14 @@ pub(crate) struct Cdfs {
287 /// `reduced_tx_set` (spec `TX_SET_INTER_3`, `TX_8X8` row) -- not indexed298 /// `reduced_tx_set` (spec `TX_SET_INTER_3`, `TX_8X8` row) -- not indexed
288 /// by mode, same as [`Self::inter_tx_type_32`] (lane-av1inter8).299 /// by mode, same as [`Self::inter_tx_type_32`] (lane-av1inter8).
289 pub inter_tx_type_8: [u16; 3],300 pub inter_tx_type_8: [u16; 3],
301+ /// [`Self::inter_tx_type_16`]'s `reduced_tx_set: false` counterpart
302+ /// (lane-cdffwd2): the twelve-symbol `EXT_TX_SET_DTT9_IDTX_1DDCT` row,
303+ /// not indexed by mode.
304+ pub inter_tx_type_16_set2: [u16; 13],
305+ /// [`Self::inter_tx_type_8`]'s `reduced_tx_set: false` counterpart
306+ /// (lane-cdffwd2): the sixteen-symbol `EXT_TX_SET_ALL16` row, not
307+ /// indexed by mode.
308+ pub inter_tx_type_8_set1: [u16; 17],
290 /// The DC sign of a chroma coefficient, shared by both chroma sets.309 /// The DC sign of a chroma coefficient, shared by both chroma sets.
291 pub dc_sign_chroma: [[u16; 3]; 3],310 pub dc_sign_chroma: [[u16; 3]; 3],
292 /// Whether an inter frame's block is coded as intra.311 /// Whether an inter frame's block is coded as intra.
@@ -522,6 +541,8 @@ impl Cdfs {
522 reset1(&mut self.inter_tx_type_32);541 reset1(&mut self.inter_tx_type_32);
523 reset1(&mut self.inter_tx_type_16);542 reset1(&mut self.inter_tx_type_16);
524 reset1(&mut self.inter_tx_type_8);543 reset1(&mut self.inter_tx_type_8);
544+ reset1(&mut self.inter_tx_type_16_set2);
545+ reset1(&mut self.inter_tx_type_8_set1);
525 reset2(&mut self.dc_sign_chroma);546 reset2(&mut self.dc_sign_chroma);
526 reset2(&mut self.intra_inter);547 reset2(&mut self.intra_inter);
527 reset3(&mut self.single_ref);548 reset3(&mut self.single_ref);
@@ -955,6 +976,8 @@ impl Cdfs {
955 inter_tx_type_32: cdf::INTER_TX_TYPE_SET3_32,976 inter_tx_type_32: cdf::INTER_TX_TYPE_SET3_32,
956 inter_tx_type_16: cdf::INTER_TX_TYPE_SET3_16,977 inter_tx_type_16: cdf::INTER_TX_TYPE_SET3_16,
957 inter_tx_type_8: cdf::INTER_TX_TYPE_SET3_8,978 inter_tx_type_8: cdf::INTER_TX_TYPE_SET3_8,
979+ inter_tx_type_16_set2: cdf::INTER_TX_TYPE_SET2_16,
980+ inter_tx_type_8_set1: cdf::INTER_TX_TYPE_SET1_8,
958 dc_sign_chroma: cdf::DC_SIGN_CHROMA,981 dc_sign_chroma: cdf::DC_SIGN_CHROMA,
959 intra_inter: cdf::INTRA_INTER,982 intra_inter: cdf::INTRA_INTER,
960 single_ref: cdf::SINGLE_REF,983 single_ref: cdf::SINGLE_REF,
@@ -1047,6 +1070,18 @@ impl Cdfs {
1047 tx_type: Some(self.inter_tx_type_16.as_mut_slice()),1070 tx_type: Some(self.inter_tx_type_16.as_mut_slice()),
1048 eob_pt_class1: None,1071 eob_pt_class1: None,
1049 },1072 },
1073+ TxbSet::Luma16InterSet1 => TxbTables {
1074+ side: 16,
1075+ txb_skip: &mut self.txb_skip_luma_16,
1076+ eob_pt: &mut self.eob_pt_256_luma,
1077+ eob_extra: &mut self.eob_extra_luma_16,
1078+ base: &mut self.base_luma_16,
1079+ base_eob: &mut self.base_eob_luma_16,
1080+ br: &mut self.br_luma_16,
1081+ dc_sign: &mut self.dc_sign_luma,
1082+ tx_type: Some(self.inter_tx_type_16_set2.as_mut_slice()),
1083+ eob_pt_class1: None,
1084+ },
1050 TxbSet::Luma8 => TxbTables {1085 TxbSet::Luma8 => TxbTables {
1051 side: 8,1086 side: 8,
1052 txb_skip: &mut self.txb_skip_luma_8,1087 txb_skip: &mut self.txb_skip_luma_8,
@@ -1107,6 +1142,18 @@ impl Cdfs {
1107 tx_type: Some(self.inter_tx_type_8.as_mut_slice()),1142 tx_type: Some(self.inter_tx_type_8.as_mut_slice()),
1108 eob_pt_class1: None,1143 eob_pt_class1: None,
1109 },1144 },
1145+ TxbSet::Luma8InterSet1 => TxbTables {
1146+ side: 8,
1147+ txb_skip: &mut self.txb_skip_luma_8,
1148+ eob_pt: &mut self.eob_pt_64_luma,
1149+ eob_extra: &mut self.eob_extra_luma_8,
1150+ base: &mut self.base_luma_8,
1151+ base_eob: &mut self.base_eob_luma_8,
1152+ br: &mut self.br_luma_8,
1153+ dc_sign: &mut self.dc_sign_luma,
1154+ tx_type: Some(self.inter_tx_type_8_set1.as_mut_slice()),
1155+ eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1),
1156+ },
1110 TxbSet::Chroma8 => TxbTables {1157 TxbSet::Chroma8 => TxbTables {
1111 side: 8,1158 side: 8,
1112 txb_skip: &mut self.txb_skip_chroma_8,1159 txb_skip: &mut self.txb_skip_chroma_8,
crates/ec-av1/src/decode.rsmodified+44 -14
@@ -400,8 +400,10 @@ enum TxClass {
400 impl TxClass {400 impl TxClass {
401 fn of(tx_type: TxType) -> Self {401 fn of(tx_type: TxType) -> Self {
402 match tx_type {402 match tx_type {
403- TxType::VDct => Self::Vert,403+ // `TX_CLASS_VERT`/`TX_CLASS_HORIZ` (`txb_common.h`'s `tx_type_to_class`)
404- TxType::HDct => Self::Horiz,404+ // key on axis alone -- FLIPADST is still ADST for this purpose.
405+ TxType::VDct | TxType::VAdst | TxType::VFlipAdst => Self::Vert,
406+ TxType::HDct | TxType::HAdst | TxType::HFlipAdst => Self::Horiz,
405 _ => Self::TwoD,407 _ => Self::TwoD,
406 }408 }
407 }409 }
@@ -599,18 +601,24 @@ fn read_coeffs(
599 }601 }
600 let mut tx_type = default_tx_type;602 let mut tx_type = default_tx_type;
601 if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() {603 if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() {
602- // The CDF row's own width names its set: 7 symbols (8 slots) is604+ // The CDF row's own width names its set (lane-cdffwd2: extended
603- // `TX_SET_INTRA_1`, 5 (6 slots) the reduced `TX_SET_INTRA_2` (the605+ // past the original two-way intra split once wider `reduced_tx_set
604- // inter sets we read share set 2's symbol order).606+ // == 0` inter sets joined the table): 17 slots (16 symbols) is
605- let set1 = tx_type_cdf.len() == 8;607+ // `EXT_TX_SET_ALL16`, 13 (12 symbols) `EXT_TX_SET_DTT9_IDTX_1DDCT`,
608+ // 8 (7 symbols) `TX_SET_INTRA_1`, everything else (6 slots, 5
609+ // symbols) the reduced `TX_SET_INTRA_2`/`TX_SET_INTER_3` two sets
610+ // share their symbol order with (`Tx_Type_Inter_Inv_Set3`'s two
611+ // members are a prefix of `Tx_Type_Intra_Inv_Set2`'s five).
612+ let len = tx_type_cdf.len();
606 let t = dec.symbol(tx_type_cdf);613 let t = dec.symbol(tx_type_cdf);
607 if trace {614 if trace {
608- eprintln!("TRACE tx_type value={t} set1={set1}");615+ eprintln!("TRACE tx_type value={t} len={len}");
609 }616 }
610- tx_type = if set1 {617+ tx_type = match len {
611- TxType::from_symbol_set1(t)618+ 17 => TxType::from_symbol_all16(t),
612- } else {619+ 13 => TxType::from_symbol_set2_12(t),
613- TxType::from_symbol(t)620+ 8 => TxType::from_symbol_set1(t),
621+ _ => TxType::from_symbol(t),
614 }622 }
615 .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?;623 .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?;
616 }624 }
@@ -5395,6 +5403,9 @@ fn decode_inter_block8(
5395 // just above).5403 // just above).
5396 skip_mode_present: bool,5404 skip_mode_present: bool,
5397 skip_mode_frame: [u8; 2],5405 skip_mode_frame: [u8; 2],
5406+ // lane-cdffwd2: this frame header's own `reduced_tx_set` bit -- see
5407+ // [`decode_inter_frame_tile_with_cdfs`]'s own doc.
5408+ reduced_tx_set: bool,
5398 // lane-av1comp: `Some((ref1, comp_group_idx, compound_idx))` only for a5409 // lane-av1comp: `Some((ref1, comp_group_idx, compound_idx))` only for a
5399 // real `COMPOUND_REFERENCE` leaf, for the caller's own end-of-16x165410 // real `COMPOUND_REFERENCE` leaf, for the caller's own end-of-16x16
5400 // `record_compound_ctx` call -- mirrors [`decode_inter_block`]'s own5411 // `record_compound_ctx` call -- mirrors [`decode_inter_block`]'s own
@@ -5718,7 +5729,11 @@ fn decode_inter_block8(
5718 luma_grid = read_inter_plane(5729 luma_grid = read_inter_plane(
5719 dec,5730 dec,
5720 cdfs,5731 cdfs,
5721- TxbSet::Luma8Inter,5732+ if reduced_tx_set {
5733+ TxbSet::Luma8Inter
5734+ } else {
5735+ TxbSet::Luma8InterSet1
5736+ },
5722 scan8,5737 scan8,
5723 0,5738 0,
5724 around[0],5739 around[0],
@@ -5912,7 +5927,11 @@ fn decode_inter_block8(
5912 luma_grid = read_inter_plane(5927 luma_grid = read_inter_plane(
5913 dec,5928 dec,
5914 cdfs,5929 cdfs,
5915- TxbSet::Luma8Inter,5930+ if reduced_tx_set {
5931+ TxbSet::Luma8Inter
5932+ } else {
5933+ TxbSet::Luma8InterSet1
5934+ },
5916 scan8,5935 scan8,
5917 0,5936 0,
5918 around[0],5937 around[0],
@@ -6160,6 +6179,7 @@ pub fn decode_inter_frame_tile(
6160 false,6179 false,
6161 false,6180 false,
6162 [0; 2],6181 [0; 2],
6182+ true,
6163 )6183 )
6164 .map(|(picture, _, _)| picture)6184 .map(|(picture, _, _)| picture)
6165 }6185 }
@@ -6205,6 +6225,11 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
6205 // `decode_inter_block8` call below.6225 // `decode_inter_block8` call below.
6206 skip_mode_present: bool,6226 skip_mode_present: bool,
6207 skip_mode_frame: [u8; 2],6227 skip_mode_frame: [u8; 2],
6228+ // lane-cdffwd2: this frame header's own `reduced_tx_set` bit, threaded to
6229+ // every inter `tx_type` read below (`false` needs the 12-/16-symbol
6230+ // `Set1` coefficient tables at 16x16/8x8 rather than the reduced
6231+ // 2-symbol ones -- see [`TxbSet::Luma16InterSet1`]/[`TxbSet::Luma8InterSet1`]).
6232+ reduced_tx_set: bool,
6208 ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> {6233 ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> {
6209 let tpl_frame = tpl_field.map(|field| TplFrameArgs {6234 let tpl_frame = tpl_field.map(|field| TplFrameArgs {
6210 field,6235 field,
@@ -6456,7 +6481,11 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
6456 &sign_bias_table,6481 &sign_bias_table,
6457 base_q_idx,6482 base_q_idx,
6458 TxbSet::Luma16,6483 TxbSet::Luma16,
6459- TxbSet::Luma16Inter,6484+ if reduced_tx_set {
6485+ TxbSet::Luma16Inter
6486+ } else {
6487+ TxbSet::Luma16InterSet1
6488+ },
6460 TxbSet::Chroma8,6489 TxbSet::Chroma8,
6461 TX16,6490 TX16,
6462 TX8,6491 TX8,
@@ -6536,6 +6565,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
6536 ref_order_hints,6565 ref_order_hints,
6537 skip_mode_present,6566 skip_mode_present,
6538 skip_mode_frame,6567 skip_mode_frame,
6568+ reduced_tx_set,
6539 )?;6569 )?;
6540 prev_leaf = Some((leaf_mi, skip, is_inter));6570 prev_leaf = Some((leaf_mi, skip, is_inter));
6541 last_skip_mode = skip_mode_leaf;6571 last_skip_mode = skip_mode_leaf;
crates/ec-av1/src/stream.rsmodified+1 -0
@@ -378,6 +378,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
378 enable_jnt_comp,378 enable_jnt_comp,
379 header.skip_mode_present,379 header.skip_mode_present,
380 header.skip_mode_frame,380 header.skip_mode_frame,
381+ header.reduced_tx_set,
381 )?382 )?
382 };383 };
383 // Spec 7.20: `disable_frame_end_update_cdf` stores the frame's384 // Spec 7.20: `disable_frame_end_update_cdf` stores the frame's
crates/ec-av1/src/transform.rsmodified+112 -3
@@ -320,6 +320,31 @@ pub enum TxType {
320 /// Identity down the column axis, DCT across the row axis320 /// Identity down the column axis, DCT across the row axis
321 /// (`H_DCT` -- `TX_SET_INTRA_1` only).321 /// (`H_DCT` -- `TX_SET_INTRA_1` only).
322 HDct,322 HDct,
323+ /// FLIPADST down the column axis, DCT across the row axis (lane-cdffwd2:
324+ /// reachable once `reduced_tx_set == false`'s wider inter sets are read
325+ /// -- `EXT_TX_SET_DTT9_IDTX_1DDCT`/`EXT_TX_SET_ALL16`). FLIPADST is the
326+ /// same 1D ADST kernel [`AdstDct`] uses (`vtx_tab`/`htx_tab`,
327+ /// `common_data.h`), just read/written flipped -- see [`TxType::flip`].
328+ FlipAdstDct,
329+ /// DCT down the column axis, FLIPADST across the row axis.
330+ DctFlipAdst,
331+ /// FLIPADST on both axes.
332+ FlipAdstFlipAdst,
333+ /// ADST down the column axis, FLIPADST across the row axis.
334+ AdstFlipAdst,
335+ /// FLIPADST down the column axis, ADST across the row axis.
336+ FlipAdstAdst,
337+ /// ADST down the column axis, identity across the row axis (`V_ADST` --
338+ /// `EXT_TX_SET_ALL16` only).
339+ VAdst,
340+ /// Identity down the column axis, ADST across the row axis (`H_ADST`).
341+ HAdst,
342+ /// FLIPADST down the column axis, identity across the row axis
343+ /// (`V_FLIPADST`).
344+ VFlipAdst,
345+ /// Identity down the column axis, FLIPADST across the row axis
346+ /// (`H_FLIPADST`).
347+ HFlipAdst,
323 }348 }
324 349
325 impl TxType {350 impl TxType {
@@ -353,6 +378,57 @@ impl TxType {
353 }378 }
354 }379 }
355 380
381+ /// The inverse of `Tx_Type_Inter_Inv_Set2`'s CDF symbol order
382+ /// (`av1_ext_tx_inv[EXT_TX_SET_DTT9_IDTX_1DDCT]`, `entropymode.h`:
383+ /// `{9, 10, 11, 0, 1, 2, 4, 5, 3, 6, 7, 8}`) -- the twelve-type set a
384+ /// `reduced_tx_set == 0` frame's 16x16 *inter* transform reads from
385+ /// (`av1_get_ext_tx_set_type`'s `tx_size_sqr == TX_16X16` branch of
386+ /// `av1_ext_tx_set_lookup[1]`).
387+ pub fn from_symbol_set2_12(t: usize) -> Option<Self> {
388+ match t {
389+ 0 => Some(Self::Idtx),
390+ 1 => Some(Self::VDct),
391+ 2 => Some(Self::HDct),
392+ 3 => Some(Self::DctDct),
393+ 4 => Some(Self::AdstDct),
394+ 5 => Some(Self::DctAdst),
395+ 6 => Some(Self::FlipAdstDct),
396+ 7 => Some(Self::DctFlipAdst),
397+ 8 => Some(Self::AdstAdst),
398+ 9 => Some(Self::FlipAdstFlipAdst),
399+ 10 => Some(Self::AdstFlipAdst),
400+ 11 => Some(Self::FlipAdstAdst),
401+ _ => None,
402+ }
403+ }
404+
405+ /// The inverse of `Tx_Type_Inter_Inv_Set1`'s CDF symbol order
406+ /// (`av1_ext_tx_inv[EXT_TX_SET_ALL16]`, `entropymode.h`:
407+ /// `{9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 4, 5, 3, 6, 7, 8}`) -- the full
408+ /// sixteen-type set a `reduced_tx_set == 0` frame's 8x8 (and 4x4) inter
409+ /// transform reads from (`av1_ext_tx_set_lookup[1][0]`).
410+ pub fn from_symbol_all16(t: usize) -> Option<Self> {
411+ match t {
412+ 0 => Some(Self::Idtx),
413+ 1 => Some(Self::VDct),
414+ 2 => Some(Self::HDct),
415+ 3 => Some(Self::VAdst),
416+ 4 => Some(Self::HAdst),
417+ 5 => Some(Self::VFlipAdst),
418+ 6 => Some(Self::HFlipAdst),
419+ 7 => Some(Self::DctDct),
420+ 8 => Some(Self::AdstDct),
421+ 9 => Some(Self::DctAdst),
422+ 10 => Some(Self::FlipAdstDct),
423+ 11 => Some(Self::DctFlipAdst),
424+ 12 => Some(Self::AdstAdst),
425+ 13 => Some(Self::FlipAdstFlipAdst),
426+ 14 => Some(Self::AdstFlipAdst),
427+ 15 => Some(Self::FlipAdstAdst),
428+ _ => None,
429+ }
430+ }
431+
356 /// `(row, col)`: the transform `inverse_transform_2d_typed`'s row pass432 /// `(row, col)`: the transform `inverse_transform_2d_typed`'s row pass
357 /// (`htx_tab`, spec/libaom "horizontal") and column pass (`vtx_tab`,433 /// (`htx_tab`, spec/libaom "horizontal") and column pass (`vtx_tab`,
358 /// "vertical") each run. Read off libaom's `av1_inv_txfm2d.c` `vtx_tab`/434 /// "vertical") each run. Read off libaom's `av1_inv_txfm2d.c` `vtx_tab`/
@@ -370,6 +446,29 @@ impl TxType {
370 // `av1_inv_txfm2d.c`: V_DCT vtx=DCT htx=IDTX, H_DCT the mirror.446 // `av1_inv_txfm2d.c`: V_DCT vtx=DCT htx=IDTX, H_DCT the mirror.
371 Self::VDct => (Identity, Dct),447 Self::VDct => (Identity, Dct),
372 Self::HDct => (Dct, Identity),448 Self::HDct => (Dct, Identity),
449+ // FLIPADST reads the same 1D ADST kernel as ADST -- `vtx_tab`/
450+ // `htx_tab` (`common_data.h`) map `FLIPADST_1D` and `ADST_1D`
451+ // to the exact same butterfly network; only [`Self::flip`]
452+ // differs. So every FLIPADST-bearing axis below mirrors its
453+ // plain-ADST counterpart's kernel pairing.
454+ Self::FlipAdstDct => (Dct, Adst),
455+ Self::DctFlipAdst => (Adst, Dct),
456+ Self::FlipAdstFlipAdst | Self::AdstFlipAdst | Self::FlipAdstAdst => (Adst, Adst),
457+ Self::VAdst | Self::VFlipAdst => (Identity, Adst),
458+ Self::HAdst | Self::HFlipAdst => (Adst, Identity),
459+ }
460+ }
461+
462+ /// `(ud_flip, lr_flip)` (`get_flip_cfg`, `av1_txfm.h`): whether the
463+ /// column pass reads its input right-to-left and/or the finished
464+ /// residual is written bottom-to-top. Every FLIPADST-bearing type sets
465+ /// one or both; every other type is `(false, false)`.
466+ fn flip(self) -> (bool, bool) {
467+ match self {
468+ Self::FlipAdstDct | Self::FlipAdstAdst | Self::VFlipAdst => (true, false),
469+ Self::DctFlipAdst | Self::AdstFlipAdst | Self::HFlipAdst => (false, true),
470+ Self::FlipAdstFlipAdst => (true, true),
471+ _ => (false, false),
373 }472 }
374 }473 }
375 }474 }
@@ -698,6 +797,7 @@ pub fn inverse_transform_2d_typed(
698 let col_clamp = (usize::from(bit_depth) + 6).max(16);797 let col_clamp = (usize::from(bit_depth) + 6).max(16);
699 let mut residual = vec![0i32; side * side];798 let mut residual = vec![0i32; side * side];
700 let (row_kind, col_kind) = tx_type.axes();799 let (row_kind, col_kind) = tx_type.axes();
800+ let (ud_flip, lr_flip) = tx_type.flip();
701 801
702 let mut t = [0i32; 64];802 let mut t = [0i32; 64];
703 for i in 0..side {803 for i in 0..side {
@@ -716,16 +816,25 @@ pub fn inverse_transform_2d_typed(
716 }816 }
717 }817 }
718 818
819+ // A FLIPADST axis reads the row-pass output right-to-left and/or writes
820+ // its own output bottom-to-top (`inv_txfm2d_add_c`, `av1_inv_txfm2d.c`
821+ // lines 291-314): `out` is a second buffer, not `residual` reused in
822+ // place, because a flipped read/write pair aliases a column this same
823+ // loop has not visited yet (column `j`'s write target under `lr_flip`
824+ // is a column an unflipped loop would still need to read from later).
825+ let mut out = vec![0i32; side * side];
719 for j in 0..side {826 for j in 0..side {
827+ let src_col = if lr_flip { side - 1 - j } else { j };
720 for i in 0..side {828 for i in 0..side {
721- t[i] = residual[i * side + j];829+ t[i] = residual[i * side + src_col];
722 }830 }
723 inverse_1d(&mut t, log2, col_clamp, col_kind);831 inverse_1d(&mut t, log2, col_clamp, col_kind);
724 for i in 0..side {832 for i in 0..side {
725- residual[i * side + j] = round2(t[i], 4);833+ let dst_row = if ud_flip { side - 1 - i } else { i };
834+ out[dst_row * side + j] = round2(t[i], 4);
726 }835 }
727 }836 }
728- residual837+ out
729 }838 }
730 839
731 /// [`inverse_transform_2d_typed`] at `DCT_DCT`, this crate's original840 /// [`inverse_transform_2d_typed`] at `DCT_DCT`, this crate's original