forge
Explore
Log in

Don't you dare go Hollow

wip(av1): reduced_tx_set=false inter tx sets -- CDFs + inverse transforms, NOT WIRED YET

Browse files at this commit

8dbd683068d7f87f21dcc4ed1dfdca786d82c52bAhmet Kaan GümüşParent: dcd3feb
Compiles clean; NOT YET reachable from any decode path (dying-words WIP,
budget exhausted mid-lane -- entropy layer is done, threading is not).

What this round did (root cause from r1: cdf_state.rs TxbSet::Luma16Inter/
Luma8Inter hardcode the reduced_tx_set=true 2-symbol table; a real aomenc
stream with reduced_tx_set=false needs wider sets there):

1. Transcribed from /tmp/libaom-src (entropymode.c:369-403, entropymode.h:
   169-185, blockd.h:1036-1122, common_data.h:149-159, av1_txfm.h:169-207,
   txb_common.h:32-47, aom_dsp/txfm_common.h:52-68):
   - av1_ext_tx_set_lookup[is_inter=1][tx_size_sqr==TX_16X16] gives, for a
     16x16 inter block, EXT_TX_SET_DTT9_IDTX_1DDCT (12 symbols) -- NOT
     DTT4_IDTX_1DDCT as the r1 handoff guessed (right symbol count, wrong
     set name); for 8x8 (and 4x4) inter, EXT_TX_SET_ALL16 (16 symbols).
   - New cdf.rs tables INTER_TX_TYPE_SET2_16 (TX_16X16 row of
     default_inter_ext_tx_cdf[EXT_TX_SET_DTT9_IDTX_1DDCT]) and
     INTER_TX_TYPE_SET1_8 (TX_8X8 row of
     default_inter_ext_tx_cdf[EXT_TX_SET_ALL16]), transcribed verbatim.
   - New cdf_state.rs storage (inter_tx_type_16_set2, inter_tx_type_8_set1),
     reset1-wired (adaptation) and seeded from the new cdf.rs tables in
     Cdfs::new -- both join the existing reset sweep so a forwarded-CDF
     frame carries them too (av1-cdffwd-three-bugs class: nothing here is a
     new table left off the forwarding/reset map).
   - New TxbSet::Luma16InterSet1/Luma8InterSet1 variants + txb() match arms.

2. Coverage check (tx-class-cross-cutting class, repo memory) -- swept
   every libaom array indexed by tx_type/tx_set for the new TxType members
   this needs (FLIPADST_DCT, DCT_FLIPADST, FLIPADST_FLIPADST, ADST_FLIPADST,
   FLIPADST_ADST, V_ADST, H_ADST, V_FLIPADST, H_FLIPADST -- 9 new variants):
   - transform.rs: TxType gained the 9 variants + from_symbol_set2_12 (12-
     symbol table, av1_ext_tx_inv[EXT_TX_SET_DTT9_IDTX_1DDCT]) +
     from_symbol_all16 (16-symbol, av1_ext_tx_inv[EXT_TX_SET_ALL16]).
   - axes(): FLIPADST reads the *same* 1D ADST kernel as ADST (common_data.h
     vtx_tab/htx_tab map both FLIPADST_1D and ADST_1D to the identical
     butterfly network) -- no new 1D transform to port, confirmed against
     av1_inv_txfm2d.c's inv_txfm2d_add_c (lines 234-316): the flip is pure
     post-processing (lr_flip reverses which column the column-pass reads,
     ud_flip reverses which output row the result lands in), never a
     different arithmetic kernel. Added TxType::flip() and rewired
     inverse_transform_2d_typed to read from an un-mutated `residual`
     buffer into a separate `out` buffer under the flip (the naive in-place
     version has a real RAW hazard: for side/2 columns, a flipped write at
     iteration j clobbers a source column iteration side-1-j will read
     later -- caught before it shipped, not left as a corner-cut).
   - decode.rs TxClass::of: V_ADST/V_FLIPADST -> Vert, H_ADST/H_FLIPADST ->
     Horiz (txb_common.h's tx_type_to_class table), matching V_DCT/H_DCT's
     existing treatment -- coefficient scan/context tables are already
     generic over TxClass, not TxType, so no further surface needed there.
   - decode.rs read_coeffs: CDF-length dispatch (already the crate's own
     idiom, doc'd at the read site) extended from 2-way to 4-way: 17 slots
     -> from_symbol_all16, 13 -> from_symbol_set2_12, 8 -> from_symbol_set1,
     else -> from_symbol (unchanged 2-/5-symbol sets).

3. NOT DONE (why this is WIP, not a fix): no call site actually threads
   reduced_tx_set into TxbSet::Luma16InterSet1/Luma8InterSet1 selection.
   decode_inter_frame_tile_with_cdfs (decode.rs:6197) does not even take a
   reduced_tx_set parameter -- the entire inter tile path hardcodes the
   reduced (2-symbol) inter tables today, unconditionally. Wiring needs:
     - reduced_tx_set: bool added to decode_inter_frame_tile/_with_cdfs
       (decode.rs:6147/6197) and its caller (stream.rs, frame-header
       reduced_tx_set bit -- already parsed for the key-frame/intra path,
       needs finding/threading for inter frames too).
     - threaded through decode_inter_block (4259) and decode_inter_block8
       (5384) as a new parameter, to their four call sites (6399, 6465,
       6535, 7307).
     - TxbSet::Luma16Inter -> Luma16InterSet1 and Luma8Inter ->
       Luma8InterSet1 selection gated on !reduced_tx_set at decode.rs:6484,
       7326 (Luma16*) and 5746, 5940 (Luma8*) -- mirroring txbset_for's
       existing reduced_tx_set match, but for the inter call sites which
       currently have no such helper.
     - the pinned repro (cdfflake-stream-seed45.bin) will not go green
       until this wiring lands; not run this round since the desync path
       is still unreached.
   Intra ext-tx (default_intra_ext_tx_cdf) was NOT re-checked for the same
   hardcoding this round -- r8's comment (Luma8Set1/Luma4Set1 exist) says
   intra's reduced_tx_set split is already handled at 8x8/4x4, and 16x16
   intra is DCT_IDTX-set-only regardless of the flag per
   av1_get_ext_tx_set_type (`tx_size_sqr == TX_16X16` branch skips the
   `use_reduced_set` check for BOTH is_inter values) -- so intra should
   already be correct, but this was reasoned, not re-verified against
   entropymode.c line by line this round.
   Also unaddressed (pre-existing, r1-noted gap): no Luma4Inter path exists
   at all in this crate -- an inter TX_4X4 transform (also EXT_TX_SET_ALL16
   under reduced_tx_set=false, TX_4X4 row of the same CDF, not yet
   transcribed) has nowhere to decode to. Out of this round's scope.
crates/ec-av1/src/cdf.rsmodified+20 -0
@@ -1105,6 +1105,26 @@ pub const INTER_TX_TYPE_SET3_16: [u16; 3] = [1998, 32768, 0];
11051105 /// `default_inter_ext_tx_cdf[EXT_TX_SET_DCT_IDTX][TX_8X8]`).
11061106 pub const INTER_TX_TYPE_SET3_8: [u16; 3] = [4167, 32768, 0];
11071107
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+
11081128 // The inter-frame tables below (spec 9.4) support the syntax an inter block
11091129 // needs: whether it is coded as intra at all, which reference frame and
11101130 // 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 {
3737 /// reads, but its own two-symbol `tx_type` table rather than `Luma16`'s
3838 /// five-symbol, mode-indexed one.
3939 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,
4047 /// The 8x8 luma transform of an intra 8x8 leaf under a straddling 16x16
4148 /// block (lane-av1-rect). An `is_inter` leaf reads
4249 /// [`Luma8Inter`](TxbSet::Luma8Inter) instead.
@@ -55,6 +62,10 @@ pub(crate) enum TxbSet {
5562 /// adapted table from the 16x16 and 32x32 sizes' own entries in the same
5663 /// set, per `entropymode.c`).
5764 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,
5869 /// The 4x4 luma transform of a `TxMode::Select` 8x8 leaf or 16x16 block
5970 /// whose `tx_depth` resolves all the way down (lane-av1tx4). An
6071 /// `is_inter` block has no writer path yet, so this crate has no
@@ -287,6 +298,14 @@ pub(crate) struct Cdfs {
287298 /// `reduced_tx_set` (spec `TX_SET_INTER_3`, `TX_8X8` row) -- not indexed
288299 /// by mode, same as [`Self::inter_tx_type_32`] (lane-av1inter8).
289300 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],
290309 /// The DC sign of a chroma coefficient, shared by both chroma sets.
291310 pub dc_sign_chroma: [[u16; 3]; 3],
292311 /// Whether an inter frame's block is coded as intra.
@@ -522,6 +541,8 @@ impl Cdfs {
522541 reset1(&mut self.inter_tx_type_32);
523542 reset1(&mut self.inter_tx_type_16);
524543 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);
525546 reset2(&mut self.dc_sign_chroma);
526547 reset2(&mut self.intra_inter);
527548 reset3(&mut self.single_ref);
@@ -955,6 +976,8 @@ impl Cdfs {
955976 inter_tx_type_32: cdf::INTER_TX_TYPE_SET3_32,
956977 inter_tx_type_16: cdf::INTER_TX_TYPE_SET3_16,
957978 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,
958981 dc_sign_chroma: cdf::DC_SIGN_CHROMA,
959982 intra_inter: cdf::INTRA_INTER,
960983 single_ref: cdf::SINGLE_REF,
@@ -1047,6 +1070,18 @@ impl Cdfs {
10471070 tx_type: Some(self.inter_tx_type_16.as_mut_slice()),
10481071 eob_pt_class1: None,
10491072 },
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+ },
10501085 TxbSet::Luma8 => TxbTables {
10511086 side: 8,
10521087 txb_skip: &mut self.txb_skip_luma_8,
@@ -1107,6 +1142,18 @@ impl Cdfs {
11071142 tx_type: Some(self.inter_tx_type_8.as_mut_slice()),
11081143 eob_pt_class1: None,
11091144 },
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+ },
11101157 TxbSet::Chroma8 => TxbTables {
11111158 side: 8,
11121159 txb_skip: &mut self.txb_skip_chroma_8,
crates/ec-av1/src/decode.rsmodified+19 -11
@@ -400,8 +400,10 @@ enum TxClass {
400400 impl TxClass {
401401 fn of(tx_type: TxType) -> Self {
402402 match tx_type {
403- TxType::VDct => Self::Vert,
404- TxType::HDct => Self::Horiz,
403+ // `TX_CLASS_VERT`/`TX_CLASS_HORIZ` (`txb_common.h`'s `tx_type_to_class`)
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,
405407 _ => Self::TwoD,
406408 }
407409 }
@@ -599,18 +601,24 @@ fn read_coeffs(
599601 }
600602 let mut tx_type = default_tx_type;
601603 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) is
603- // `TX_SET_INTRA_1`, 5 (6 slots) the reduced `TX_SET_INTRA_2` (the
604- // inter sets we read share set 2's symbol order).
605- let set1 = tx_type_cdf.len() == 8;
604+ // The CDF row's own width names its set (lane-cdffwd2: extended
605+ // past the original two-way intra split once wider `reduced_tx_set
606+ // == 0` inter sets joined the table): 17 slots (16 symbols) is
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();
606613 let t = dec.symbol(tx_type_cdf);
607614 if trace {
608- eprintln!("TRACE tx_type value={t} set1={set1}");
615+ eprintln!("TRACE tx_type value={t} len={len}");
609616 }
610- tx_type = if set1 {
611- TxType::from_symbol_set1(t)
612- } else {
613- TxType::from_symbol(t)
617+ tx_type = match len {
618+ 17 => TxType::from_symbol_all16(t),
619+ 13 => TxType::from_symbol_set2_12(t),
620+ 8 => TxType::from_symbol_set1(t),
621+ _ => TxType::from_symbol(t),
614622 }
615623 .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?;
616624 }
crates/ec-av1/src/transform.rsmodified+112 -3
@@ -320,6 +320,31 @@ pub enum TxType {
320320 /// Identity down the column axis, DCT across the row axis
321321 /// (`H_DCT` -- `TX_SET_INTRA_1` only).
322322 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,
323348 }
324349
325350 impl TxType {
@@ -353,6 +378,57 @@ impl TxType {
353378 }
354379 }
355380
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+
356432 /// `(row, col)`: the transform `inverse_transform_2d_typed`'s row pass
357433 /// (`htx_tab`, spec/libaom "horizontal") and column pass (`vtx_tab`,
358434 /// "vertical") each run. Read off libaom's `av1_inv_txfm2d.c` `vtx_tab`/
@@ -370,6 +446,29 @@ impl TxType {
370446 // `av1_inv_txfm2d.c`: V_DCT vtx=DCT htx=IDTX, H_DCT the mirror.
371447 Self::VDct => (Identity, Dct),
372448 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),
373472 }
374473 }
375474 }
@@ -698,6 +797,7 @@ pub fn inverse_transform_2d_typed(
698797 let col_clamp = (usize::from(bit_depth) + 6).max(16);
699798 let mut residual = vec![0i32; side * side];
700799 let (row_kind, col_kind) = tx_type.axes();
800+ let (ud_flip, lr_flip) = tx_type.flip();
701801
702802 let mut t = [0i32; 64];
703803 for i in 0..side {
@@ -716,16 +816,25 @@ pub fn inverse_transform_2d_typed(
716816 }
717817 }
718818
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];
719826 for j in 0..side {
827+ let src_col = if lr_flip { side - 1 - j } else { j };
720828 for i in 0..side {
721- t[i] = residual[i * side + j];
829+ t[i] = residual[i * side + src_col];
722830 }
723831 inverse_1d(&mut t, log2, col_clamp, col_kind);
724832 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);
726835 }
727836 }
728- residual
837+ out
729838 }
730839
731840 /// [`inverse_transform_2d_typed`] at `DCT_DCT`, this crate's original